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)
{
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));
}
static ConstructorInfo GetDefaultConstructor (Type type)