Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / System.Core / System.Linq.Expressions / NewExpression.cs
index ec6b1b795de4c5e1db8ccbb973b806452df66a9e..005d17569ec8d9c4943cd897e927b59b4bb0973d 100644 (file)
@@ -51,6 +51,12 @@ namespace System.Linq.Expressions {
                        get { return members; }
                }
 
+               internal NewExpression (Type type, ReadOnlyCollection<Expression> arguments)
+                       : base (ExpressionType.New, type)
+               {
+                       this.arguments = arguments;
+               }
+
                internal NewExpression (ConstructorInfo constructor, ReadOnlyCollection<Expression> arguments, ReadOnlyCollection<MemberInfo> members)
                        : base (ExpressionType.New, constructor.DeclaringType)
                {
@@ -59,19 +65,33 @@ namespace System.Linq.Expressions {
                        this.members = members;
                }
 
+#if !FULL_AOT_RUNTIME
                internal override void Emit (EmitContext ec)
                {
                        var ig = ec.ig;
+                       var type = this.Type;
+
+                       LocalBuilder local = null;
+                       if (type.IsValueType) {
+                               local = ig.DeclareLocal (type);
+                               ig.Emit (OpCodes.Ldloca, local);
 
-                       bool is_value_type = this.Type.IsValueType;
-                       if (is_value_type)
-                               throw new NotImplementedException ();
+                               if (constructor == null) {
+                                       ig.Emit (OpCodes.Initobj, type);
+                                       ig.Emit (OpCodes.Ldloc, local);
+                                       return;
+                               }
+                       }
 
-                       foreach (var arg in arguments)
-                               arg.Emit (ec);
+                       ec.EmitCollection (arguments);
 
-                       ig.Emit (OpCodes.Newobj, constructor ?? GetDefaultConstructor (this.Type));
+                       if (type.IsValueType) {
+                               ig.Emit (OpCodes.Call, constructor);
+                               ig.Emit (OpCodes.Ldloc, local);
+                       } else
+                               ig.Emit (OpCodes.Newobj, constructor ?? GetDefaultConstructor (type));
                }
+#endif
 
                static ConstructorInfo GetDefaultConstructor (Type type)
                {