New tests, update.
[mono.git] / mcs / class / System.Core / System.Linq.Expressions / NewExpression.cs
index b4c2398f1a064f024071b0d0e28b80bf22e2104b..8e6673c616c8b7714708969cfe65d909cee858df 100644 (file)
@@ -68,15 +68,27 @@ namespace System.Linq.Expressions {
                internal override void Emit (EmitContext ec)
                {
                        var ig = ec.ig;
+                       var type = this.Type;
 
-                       bool is_value_type = this.Type.IsValueType;
-                       if (is_value_type)
-                               throw new NotImplementedException ();
+                       LocalBuilder local = null;
+                       if (type.IsValueType) {
+                               local = ig.DeclareLocal (type);
+                               ig.Emit (OpCodes.Ldloca, local);
 
-                       foreach (var arg in arguments)
-                               arg.Emit (ec);
+                               if (constructor == null) {
+                                       ig.Emit (OpCodes.Initobj, type);
+                                       ig.Emit (OpCodes.Ldloc, local);
+                                       return;
+                               }
+                       }
 
-                       ig.Emit (OpCodes.Newobj, constructor ?? GetDefaultConstructor (this.Type));
+                       ec.EmitCollection (arguments);
+
+                       if (type.IsValueType) {
+                               ig.Emit (OpCodes.Call, constructor);
+                               ig.Emit (OpCodes.Ldloc, local);
+                       } else
+                               ig.Emit (OpCodes.Newobj, constructor ?? GetDefaultConstructor (type));
                }
 
                static ConstructorInfo GetDefaultConstructor (Type type)