C# Class LinFu.Reflection.Emit.CilWorkerExtensions

A class that extends the CilWorker class with helper methods that make it easier to save information about the method currently being implemented.
Datei anzeigen Open project: philiplaureano/LinFu

Public Methods

Method Description
EmitWriteLine ( this IL, string text ) : void

Emits a Console.WriteLine call using the current CilWorker.

EmitWriteLineIfNull ( this IL, string text, Mono.Cecil.Cil.VariableDefinition targetVariable ) : void

Emits a Console.WriteLine call to using the current CilWorker that will only be called if the contents of the target variable are null at runtime.

GetDeclaringType ( this method ) : TypeReference

Gets the declaring type for the target method.

GetMethod ( this IL ) : Mono.Cecil.MethodDefinition

Obtains the method definition that contains the current CilWorker.

GetModule ( this IL ) : Mono.Cecil.ModuleDefinition

Obtains the module that contains the current CilWorker.

PackageReturnValue ( this IL, Mono.Cecil.ModuleDefinition module, TypeReference returnType ) : void

Converts the return value of a method into the target type. If the target type is void, then the value will simply be popped from the stack.

PushArguments ( this IL, IMethodSignature method, Mono.Cecil.ModuleDefinition module, Mono.Cecil.Cil.VariableDefinition arguments ) : void

Pushes the arguments of a method onto the stack.

PushField ( this IL, FieldReference field, Mono.Cecil.ModuleDefinition module ) : void

Pushes the current field onto the stack.

PushGenericArguments ( this IL, IGenericParameterProvider method, Mono.Cecil.ModuleDefinition module, Mono.Cecil.Cil.VariableDefinition typeArguments ) : void

Saves the generic type arguments that were used to construct the method.

PushMethod ( this IL, MethodReference method, Mono.Cecil.ModuleDefinition module ) : void

Pushes the current method onto the stack.

PushStackTrace ( this IL, Mono.Cecil.ModuleDefinition module ) : void

Pushes the stack trace of the currently executing method onto the stack.

PushType ( this IL, TypeReference type, Mono.Cecil.ModuleDefinition module ) : void

Pushes a Type instance onto the stack.

SaveParameterTypes ( this IL, MethodReference method, Mono.Cecil.ModuleDefinition module, Mono.Cecil.Cil.VariableDefinition parameterTypes ) : void

Saves the current method signature of a method into an array of System.Type objects. This can be used to determine the signature of methods with generic type parameters or methods that have parameters that are generic parameters specified by the type itself.

Stind ( this IL, TypeReference currentType ) : void

Emits the proper Stind (store indirect) IL instruction for the currentType.

Private Methods

Method Description
CilWorkerExtensions ( ) : System
GetDeclaringType ( TypeReference declaringType ) : TypeReference

Obtains the declaring type for a given type reference.

PushParameter ( this IL, int index, Mono.Cecil.Cil.VariableDefinition arguments, Mono.Cecil.ParameterDefinition param ) : void

Stores the current parameter value into the array of method arguments.

Method Details

EmitWriteLine() public static method

Emits a Console.WriteLine call using the current CilWorker.
public static EmitWriteLine ( this IL, string text ) : void
IL this The target CilWorker.
text string The text that will be written to the console.
return void

EmitWriteLineIfNull() public static method

Emits a Console.WriteLine call to using the current CilWorker that will only be called if the contents of the target variable are null at runtime.
public static EmitWriteLineIfNull ( this IL, string text, Mono.Cecil.Cil.VariableDefinition targetVariable ) : void
IL this The target CilWorker.
text string The text that will be written to the console.
targetVariable Mono.Cecil.Cil.VariableDefinition The target variable that will be checked for null at runtime.
return void

GetDeclaringType() public static method

Gets the declaring type for the target method.
public static GetDeclaringType ( this method ) : TypeReference
method this The target method.
return Mono.Cecil.TypeReference

GetMethod() public static method

Obtains the method definition that contains the current CilWorker.
public static GetMethod ( this IL ) : Mono.Cecil.MethodDefinition
IL this The responsible for the method body.
return Mono.Cecil.MethodDefinition

GetModule() public static method

Obtains the module that contains the current CilWorker.
public static GetModule ( this IL ) : Mono.Cecil.ModuleDefinition
IL this The responsible for the method body.
return Mono.Cecil.ModuleDefinition

PackageReturnValue() public static method

Converts the return value of a method into the target type. If the target type is void, then the value will simply be popped from the stack.
public static PackageReturnValue ( this IL, Mono.Cecil.ModuleDefinition module, TypeReference returnType ) : void
IL this The that will be used to create the instructions.
module Mono.Cecil.ModuleDefinition The module that contains the host method.
returnType Mono.Cecil.TypeReference The method return type itself.
return void

PushArguments() public static method

Pushes the arguments of a method onto the stack.
public static PushArguments ( this IL, IMethodSignature method, Mono.Cecil.ModuleDefinition module, Mono.Cecil.Cil.VariableDefinition arguments ) : void
IL this The that will be used to create the instructions.
method IMethodSignature The target method.
module Mono.Cecil.ModuleDefinition The module that contains the host method.
arguments Mono.Cecil.Cil.VariableDefinition The local variable that will hold the array of arguments.
return void

PushField() public static method

Pushes the current field onto the stack.
public static PushField ( this IL, FieldReference field, Mono.Cecil.ModuleDefinition module ) : void
IL this The that will be used to create the instructions.
field Mono.Cecil.FieldReference The field that represents the that will be pushed onto the stack.
module Mono.Cecil.ModuleDefinition The module that contains the target field.
return void

PushGenericArguments() public static method

Saves the generic type arguments that were used to construct the method.
public static PushGenericArguments ( this IL, IGenericParameterProvider method, Mono.Cecil.ModuleDefinition module, Mono.Cecil.Cil.VariableDefinition typeArguments ) : void
IL this The that will be used to create the instructions.
method IGenericParameterProvider The target method whose generic type arguments (if any) will be saved into the local variable.
module Mono.Cecil.ModuleDefinition The module that contains the host method.
typeArguments Mono.Cecil.Cil.VariableDefinition The local variable that will store the resulting array of objects.
return void

PushMethod() public static method

Pushes the current method onto the stack.
public static PushMethod ( this IL, MethodReference method, Mono.Cecil.ModuleDefinition module ) : void
IL this The that will be used to create the instructions.
method Mono.Cecil.MethodReference The method that represents the that will be pushed onto the stack.
module Mono.Cecil.ModuleDefinition The module that contains the host method.
return void

PushStackTrace() public static method

Pushes the stack trace of the currently executing method onto the stack.
public static PushStackTrace ( this IL, Mono.Cecil.ModuleDefinition module ) : void
IL this The that will be used to create the instructions.
module Mono.Cecil.ModuleDefinition The module that contains the host method.
return void

PushType() public static method

Pushes a Type instance onto the stack.
public static PushType ( this IL, TypeReference type, Mono.Cecil.ModuleDefinition module ) : void
IL this The that will be used to create the instructions.
type Mono.Cecil.TypeReference The type that represents the that will be pushed onto the stack.
module Mono.Cecil.ModuleDefinition The module that contains the host method.
return void

SaveParameterTypes() public static method

Saves the current method signature of a method into an array of System.Type objects. This can be used to determine the signature of methods with generic type parameters or methods that have parameters that are generic parameters specified by the type itself.
public static SaveParameterTypes ( this IL, MethodReference method, Mono.Cecil.ModuleDefinition module, Mono.Cecil.Cil.VariableDefinition parameterTypes ) : void
IL this The that will be used to create the instructions.
method Mono.Cecil.MethodReference The target method whose generic type arguments (if any) will be saved into the local variable .
module Mono.Cecil.ModuleDefinition The module that contains the host method.
parameterTypes Mono.Cecil.Cil.VariableDefinition The local variable that will store the current method signature.
return void

Stind() public static method

Emits the proper Stind (store indirect) IL instruction for the currentType.
public static Stind ( this IL, TypeReference currentType ) : void
IL this The target that will emit the IL.
currentType Mono.Cecil.TypeReference The type of data being stored.
return void