public EmitNewarr ( Action |
||
arrayLoadingEmitter | Action |
/// Delegate to emittion of array loading instruction.
/// 1st argument is this instance.
/// Post condition is that exactly one target array will be added on the top of stack and element type is |
arrayStoringEmitter | Action |
/// Delegate to emittion of array storing instruction.
/// 1st argument is this instance.
/// Pre condition is that the top of evaluation stack is array type and its element type is |
elementType | Type | |
return | void |
public static void EmitConstruction( TracingILGenerator il, LocalBuilder target, Action<TracingILGenerator> initialCountLoadingEmitter ) { Contract.Requires( il != null ); Contract.Requires( target != null ); Contract.Requires( initialCountLoadingEmitter != null ); // TODO: For collection, supports .ctor(IEnumerable<> other) if ( target.LocalType.IsArray ) { initialCountLoadingEmitter( il ); il.EmitNewarr( target.LocalType.GetElementType() ); il.EmitAnyStloc( target ); return; } ConstructorInfo ctor = target.LocalType.GetConstructor( _ctor_Int32_ParameterTypes ); if ( ctor != null && initialCountLoadingEmitter != null && typeof( IEnumerable ).IsAssignableFrom( target.LocalType ) ) { if ( target.LocalType.IsValueType ) { // Same as general method call var capacity = il.DeclareLocal( typeof( int ), "capacity" ); initialCountLoadingEmitter( il ); il.EmitAnyStloc( capacity ); il.EmitAnyLdloca( target ); il.EmitAnyLdloc( capacity ); il.EmitCallConstructor( ctor ); } else { initialCountLoadingEmitter( il ); il.EmitNewobj( ctor ); il.EmitAnyStloc( target ); } return; } if ( target.LocalType.IsValueType ) { // ValueType instance has been initialized by the runtime. return; } ctor = target.LocalType.GetConstructor( Type.EmptyTypes ); if ( ctor == null ) { throw SerializationExceptions.NewTargetDoesNotHavePublicDefaultConstructorNorInitialCapacity( target.LocalType ); } il.EmitNewobj( ctor ); il.EmitAnyStloc( target ); }