using System;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Reflection.Emit;
namespace System.Linq.Expressions
{
/// Represents a constructor call.
// Token: 0x0200002D RID: 45
public sealed class NewExpression : Expression
{
// Token: 0x06000241 RID: 577 RVA: 0x0000BEE8 File Offset: 0x0000A0E8
internal NewExpression(Type type, ReadOnlyCollection arguments)
: base(ExpressionType.New, type)
{
this.arguments = arguments;
}
// Token: 0x06000242 RID: 578 RVA: 0x0000BEFC File Offset: 0x0000A0FC
internal NewExpression(ConstructorInfo constructor, ReadOnlyCollection arguments, ReadOnlyCollection members)
: base(ExpressionType.New, constructor.DeclaringType)
{
this.constructor = constructor;
this.arguments = arguments;
this.members = members;
}
/// Gets the called constructor.
/// The that represents the called constructor.
// Token: 0x17000030 RID: 48
// (get) Token: 0x06000243 RID: 579 RVA: 0x0000BF24 File Offset: 0x0000A124
public ConstructorInfo Constructor
{
get
{
return this.constructor;
}
}
/// Gets the arguments to the constructor.
/// A collection of objects that represent the arguments to the constructor.
// Token: 0x17000031 RID: 49
// (get) Token: 0x06000244 RID: 580 RVA: 0x0000BF2C File Offset: 0x0000A12C
public ReadOnlyCollection Arguments
{
get
{
return this.arguments;
}
}
/// Gets the members that can retrieve the values of the fields that were initialized with constructor arguments.
/// A collection of objects that represent the members that can retrieve the values of the fields that were initialized with constructor arguments.
// Token: 0x17000032 RID: 50
// (get) Token: 0x06000245 RID: 581 RVA: 0x0000BF34 File Offset: 0x0000A134
public ReadOnlyCollection Members
{
get
{
return this.members;
}
}
// Token: 0x06000246 RID: 582 RVA: 0x0000BF3C File Offset: 0x0000A13C
internal override void Emit(EmitContext ec)
{
ILGenerator ig = ec.ig;
Type type = base.Type;
LocalBuilder localBuilder = null;
if (type.IsValueType)
{
localBuilder = ig.DeclareLocal(type);
ig.Emit(OpCodes.Ldloca, localBuilder);
if (this.constructor == null)
{
ig.Emit(OpCodes.Initobj, type);
ig.Emit(OpCodes.Ldloc, localBuilder);
return;
}
}
ec.EmitCollection(this.arguments);
if (type.IsValueType)
{
ig.Emit(OpCodes.Call, this.constructor);
ig.Emit(OpCodes.Ldloc, localBuilder);
}
else
{
ig.Emit(OpCodes.Newobj, this.constructor ?? NewExpression.GetDefaultConstructor(type));
}
}
// Token: 0x06000247 RID: 583 RVA: 0x0000BFF4 File Offset: 0x0000A1F4
private static ConstructorInfo GetDefaultConstructor(Type type)
{
return type.GetConstructor(Type.EmptyTypes);
}
// Token: 0x040000BA RID: 186
private ConstructorInfo constructor;
// Token: 0x040000BB RID: 187
private ReadOnlyCollection arguments;
// Token: 0x040000BC RID: 188
private ReadOnlyCollection members;
}
}