EmitCall() public method

Emit 'call' instruction with specified arguments.
public EmitCall ( System target ) : void
target System as target.
return void
		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 );
				}
			}
		}
示例#2
0
		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 );
				}
			}
		}