C# Class CK.Reflection.ILGeneratorExtension

Provides extension methods on ILGenerator class.
Show file Open project: Invenietis/ck-core

Public Methods

Method Description
CreateObjectArrayFromInstanceParameters ( this g, LocalBuilder array, Type parameters ) : void

Emits the IL to create a new array (OpCodes.Newarr) of objects and fills it with the actual arguments of the method (parameters are boxed if needed) skipping the very first one: this must be used only inside a method with System.Reflection.CallingConventions.HasThis set.

LdArg ( this g, int i ) : void

Emits the IL to push (OpCodes.Ldarg) the actual argument at the given index onto the stack.

LdArgBox ( this g, ParameterInfo p ) : void

Emits a LdArg with an optional OpCodes.Box if p's type is a value type or a generic parameter (after a OpCodes.Ldobj if the parameter is by ref). Handles static or instance methods (takes care of System.Reflection.CallingConventions.HasThis bit of the method's CallingConvention).

LdArgBox ( this g, int idxParameter, Type parameterType ) : void

Emits a LdArg with a OpCodes.Box if parameterType is a value type or a generic parameter (after a OpCodes.Ldobj if the parameter is by ref).

LdInt32 ( this g, int i ) : void

Emits the IL to push the integer (emits the best opcode depending on the value: OpCodes.Ldc_I4_0 or OpCodes.Ldc_I4_M1 for instance) value onto the stack.

LdLoc ( this g, LocalBuilder local ) : void

Emits the IL to push (OpCodes.Ldloc) the given local on top of the stack.

RepushActualParameters ( this g, bool startAtArgument0, int count ) : void

Emits the optimal IL to push the actual parameter values on the stack (OpCodes.Ldarg_0... OpCodes.Ldarg).

StArg ( this g, int i ) : void

Emits the IL to pop (OpCodes.Starg) the top of the stack into the actual argument at the given index.

StLoc ( this g, LocalBuilder local ) : void

Emits the IL to pop (OpCodes.Stloc) the top of the stack into a local variable.

StoreDefaultValueForOutParameter ( this g, ParameterInfo byRefParameter ) : void

Emits code that sets the parameter (that must be a 'ref' or 'out' parameter) to the default of its type. Handles static or instance methods and value or reference type.

Method Details

CreateObjectArrayFromInstanceParameters() public static method

Emits the IL to create a new array (OpCodes.Newarr) of objects and fills it with the actual arguments of the method (parameters are boxed if needed) skipping the very first one: this must be used only inside a method with System.Reflection.CallingConventions.HasThis set.
public static CreateObjectArrayFromInstanceParameters ( this g, LocalBuilder array, Type parameters ) : void
g this This object.
array System.Reflection.Emit.LocalBuilder The local variable.
parameters System.Type Type of the method parameters.
return void

LdArg() public static method

Emits the IL to push (OpCodes.Ldarg) the actual argument at the given index onto the stack.
public static LdArg ( this g, int i ) : void
g this This object.
i int Parameter index (0 being the 'this' for instance method).
return void

LdArgBox() public static method

Emits a LdArg with an optional OpCodes.Box if p's type is a value type or a generic parameter (after a OpCodes.Ldobj if the parameter is by ref). Handles static or instance methods (takes care of System.Reflection.CallingConventions.HasThis bit of the method's CallingConvention).
public static LdArgBox ( this g, ParameterInfo p ) : void
g this This object.
p System.Reflection.ParameterInfo Parameter of the current method.
return void

LdArgBox() public static method

Emits a LdArg with a OpCodes.Box if parameterType is a value type or a generic parameter (after a OpCodes.Ldobj if the parameter is by ref).
public static LdArgBox ( this g, int idxParameter, Type parameterType ) : void
g this This object.
idxParameter int Index of the parameter to load on the stack.
parameterType System.Type Type of the parameter.
return void

LdInt32() public static method

Emits the IL to push the integer (emits the best opcode depending on the value: OpCodes.Ldc_I4_0 or OpCodes.Ldc_I4_M1 for instance) value onto the stack.
public static LdInt32 ( this g, int i ) : void
g this This object.
i int The integer value to push.
return void

LdLoc() public static method

Emits the IL to push (OpCodes.Ldloc) the given local on top of the stack.
public static LdLoc ( this g, LocalBuilder local ) : void
g this This object.
local System.Reflection.Emit.LocalBuilder The local variable to push.
return void

RepushActualParameters() public static method

Emits the optimal IL to push the actual parameter values on the stack (OpCodes.Ldarg_0... OpCodes.Ldarg).
public static RepushActualParameters ( this g, bool startAtArgument0, int count ) : void
g this This object.
startAtArgument0 bool False to skip the very first argument: for a method instance Arg0 is the 'this' object (see ) HasThis and ExplicitThis).
count int Number of parameters to push.
return void

StArg() public static method

Emits the IL to pop (OpCodes.Starg) the top of the stack into the actual argument at the given index.
public static StArg ( this g, int i ) : void
g this This object.
i int Parameter index (0 being the 'this' for instance method).
return void

StLoc() public static method

Emits the IL to pop (OpCodes.Stloc) the top of the stack into a local variable.
public static StLoc ( this g, LocalBuilder local ) : void
g this This object.
local System.Reflection.Emit.LocalBuilder The local variable to pop.
return void

StoreDefaultValueForOutParameter() public static method

Emits code that sets the parameter (that must be a 'ref' or 'out' parameter) to the default of its type. Handles static or instance methods and value or reference type.
public static StoreDefaultValueForOutParameter ( this g, ParameterInfo byRefParameter ) : void
g this This object.
byRefParameter System.Reflection.ParameterInfo The 'by ref' parameter.
return void