109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Reflection;
|
|
using System.Reflection.Emit;
|
|
|
|
namespace System.Linq.Expressions
|
|
{
|
|
/// <summary>Represents a constructor call.</summary>
|
|
// Token: 0x0200002D RID: 45
|
|
public sealed class NewExpression : Expression
|
|
{
|
|
// Token: 0x06000241 RID: 577 RVA: 0x0000BEE8 File Offset: 0x0000A0E8
|
|
internal NewExpression(Type type, ReadOnlyCollection<Expression> arguments)
|
|
: base(ExpressionType.New, type)
|
|
{
|
|
this.arguments = arguments;
|
|
}
|
|
|
|
// Token: 0x06000242 RID: 578 RVA: 0x0000BEFC File Offset: 0x0000A0FC
|
|
internal NewExpression(ConstructorInfo constructor, ReadOnlyCollection<Expression> arguments, ReadOnlyCollection<MemberInfo> members)
|
|
: base(ExpressionType.New, constructor.DeclaringType)
|
|
{
|
|
this.constructor = constructor;
|
|
this.arguments = arguments;
|
|
this.members = members;
|
|
}
|
|
|
|
/// <summary>Gets the called constructor.</summary>
|
|
/// <returns>The <see cref="T:System.Reflection.ConstructorInfo" /> that represents the called constructor.</returns>
|
|
// Token: 0x17000030 RID: 48
|
|
// (get) Token: 0x06000243 RID: 579 RVA: 0x0000BF24 File Offset: 0x0000A124
|
|
public ConstructorInfo Constructor
|
|
{
|
|
get
|
|
{
|
|
return this.constructor;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the arguments to the constructor.</summary>
|
|
/// <returns>A collection of <see cref="T:System.Linq.Expressions.Expression" /> objects that represent the arguments to the constructor.</returns>
|
|
// Token: 0x17000031 RID: 49
|
|
// (get) Token: 0x06000244 RID: 580 RVA: 0x0000BF2C File Offset: 0x0000A12C
|
|
public ReadOnlyCollection<Expression> Arguments
|
|
{
|
|
get
|
|
{
|
|
return this.arguments;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the members that can retrieve the values of the fields that were initialized with constructor arguments.</summary>
|
|
/// <returns>A collection of <see cref="T:System.Reflection.MemberInfo" /> objects that represent the members that can retrieve the values of the fields that were initialized with constructor arguments.</returns>
|
|
// Token: 0x17000032 RID: 50
|
|
// (get) Token: 0x06000245 RID: 581 RVA: 0x0000BF34 File Offset: 0x0000A134
|
|
public ReadOnlyCollection<MemberInfo> 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<Expression>(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<Expression> arguments;
|
|
|
|
// Token: 0x040000BC RID: 188
|
|
private ReadOnlyCollection<MemberInfo> members;
|
|
}
|
|
}
|