本文整理匯總了C#中MsgPack.Serialization.Reflection.TracingILGenerator.EmitNewarr方法的典型用法代碼示例。如果您正苦於以下問題:C# TracingILGenerator.EmitNewarr方法的具體用法?C# TracingILGenerator.EmitNewarr怎麽用?C# TracingILGenerator.EmitNewarr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MsgPack.Serialization.Reflection.TracingILGenerator
的用法示例。
在下文中一共展示了TracingILGenerator.EmitNewarr方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: EmitConstruction
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 );
}