當前位置: 首頁>>代碼示例>>C#>>正文


C# TracingILGenerator.EmitCallConstructor方法代碼示例

本文整理匯總了C#中MsgPack.Serialization.Reflection.TracingILGenerator.EmitCallConstructor方法的典型用法代碼示例。如果您正苦於以下問題:C# TracingILGenerator.EmitCallConstructor方法的具體用法?C# TracingILGenerator.EmitCallConstructor怎麽用?C# TracingILGenerator.EmitCallConstructor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MsgPack.Serialization.Reflection.TracingILGenerator的用法示例。


在下文中一共展示了TracingILGenerator.EmitCallConstructor方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 );
		}
開發者ID:purplecow,項目名稱:msgpack-cli,代碼行數:53,代碼來源:Emittion.cs

示例2: EmitMethodEnumConstructor

		private void EmitMethodEnumConstructor( Type baseType, TracingILGenerator il )
		{
			/*
			 *	.ctor( SerializationContext c, EnumSerializerMethod method ) 
			 *	  : base( c, method )
			 *	{
			 *	}
			 */
			// : base( c, method )
			il.EmitLdarg_0();
			il.EmitLdarg_1();
			il.EmitLdarg_2();

			il.EmitCallConstructor(
				baseType.GetRuntimeConstructor( ContextAndEnumSerializationMethodConstructorParameterTypes )
			);

			il.EmitRet();
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:19,代碼來源:SerializerEmitter.enum.cs

示例3: Invoke

		private void Invoke( TracingILGenerator il )
		{
			ConstructorInfo asConsctructor;
			if ( ( asConsctructor = this._method as ConstructorInfo ) != null )
			{
				if ( asConsctructor.DeclaringType.GetIsValueType() )
				{
					this._target.LoadValue( il, true );
					foreach ( var argument in this._arguments )
					{
						argument.LoadValue( il, false );
					}

					il.EmitCallConstructor( asConsctructor );

					// For compatibility to ref type.
					this._target.LoadValue( il, false );
				}
				else
				{
					foreach ( var argument in this._arguments )
					{
						argument.LoadValue( il, false );
					}

					il.EmitNewobj( asConsctructor );
				}
			}
			else
			{
				// method
				if ( !this._method.IsStatic )
				{
					this._target.LoadValue( il, this._target.ContextType.ResolveRuntimeType().GetIsValueType() );
				}

				foreach ( var argument in this._arguments )
				{
					argument.LoadValue( il, false );
				}

				if ( this._method.IsStatic || this._target.ContextType.ResolveRuntimeType().GetIsValueType() )
				{
					il.EmitCall( this._method as MethodInfo );
				}
				else if ( this._interface != null )
				{
					// Explicit interface impl
					il.EmitCallvirt(
						this._interface.GetRuntimeMethod(
							this._method.Name.Substring( this._method.Name.LastIndexOf( '.' ) + 1 ),
							this._method.GetParameterTypes()
						)
					);
				}
				else
				{
					il.EmitCallvirt( this._method as MethodInfo );
				}
			}
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:61,代碼來源:InvocationILConsruct.cs

示例4: EmitDefaultEnumConstructor

		private void EmitDefaultEnumConstructor( ConstructorBuilder methodConstructor, TracingILGenerator il )
		{
			/*
			 *	.ctor( SerializationContext c ) 
			 *	  : this( c, DEFAULT_METHOD )
			 *	{
			 *	}
			 */
			// : this( c, DEFAULT_METHOD )
			il.EmitLdarg_0();
			il.EmitLdarg_1();
			il.EmitAnyLdc_I4( ( int )this._defaultEnumSerializationMethod );

			il.EmitCallConstructor( methodConstructor );

			il.EmitRet();
		}
開發者ID:msgpack,項目名稱:msgpack-cli,代碼行數:17,代碼來源:SerializerEmitter.enum.cs

示例5: Invoke

		private void Invoke( TracingILGenerator il )
		{
			ConstructorInfo asConsctructor;
			if ( ( asConsctructor = this._method as ConstructorInfo ) != null )
			{
				if ( asConsctructor.DeclaringType.GetIsValueType() )
				{
					this._target.LoadValue( il, true );
					foreach ( var argument in this._arguments )
					{
						argument.LoadValue( il, false );
					}

					il.EmitCallConstructor( asConsctructor );

					// For compatibility to ref type.
					this._target.LoadValue( il, false );
				}
				else
				{
					foreach ( var argument in this._arguments )
					{
						argument.LoadValue( il, false );
					}

					il.EmitNewobj( asConsctructor );
				}
			}
			else
			{
				// method
				if ( !this._method.IsStatic )
				{
					this._target.LoadValue( il, this._target.ContextType.GetIsValueType() );
				}

				foreach ( var argument in this._arguments )
				{
					argument.LoadValue( il, false );
				}

				if ( this._method.IsStatic || this._target.ContextType.GetIsValueType() )
				{
					il.EmitCall( this._method as MethodInfo );
				}
				else
				{
					il.EmitCallvirt( this._method as MethodInfo );
				}
			}
		}
開發者ID:gezidan,項目名稱:ZYSOCKET,代碼行數:51,代碼來源:InvocationILConsruct.cs


注:本文中的MsgPack.Serialization.Reflection.TracingILGenerator.EmitCallConstructor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。