Show / Hide Table of Contents

Class CilExtensions

A collection of extension methods that provide an alternative syntax for some static methods of this library

Inheritance
System.Object
CilExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: CilTools.BytecodeAnalysis.Extensions
Assembly: CilTools.BytecodeAnalysis.dll
Syntax
public static class CilExtensions

Methods

EmitCilGraph(ILGenerator, CilGraph, Func<CilInstruction, Boolean>)

Emits the entire content of CIL graph into the specified IL generator, optionally calling user callback for each processed instruction.

Declaration
public static void EmitCilGraph(this ILGenerator ilg, CilGraph graph, Func<CilInstruction, bool> callback = null)
Parameters
Type Name Description
System.Reflection.Emit.ILGenerator ilg

Target IL generator.

CilGraph graph

The CIL graph which content should be emitted.

System.Func<CilInstruction, System.Boolean> callback

User callback to be called for each processed instruction.

Remarks

Passing user callback into this method enables you to filter instructions that you want to be emitted into target IL generator. Return true to skip emitting instruction, or false to emit instruction.

EmitInstruction(ILGenerator, CilInstruction)

Emits CIL code for the specified instruction into the specified IL generator.

Declaration
public static void EmitInstruction(this ILGenerator ilg, CilInstruction instr)
Parameters
Type Name Description
System.Reflection.Emit.ILGenerator ilg

Target IL generator.

CilInstruction instr

IL instruction to be emitted.

GetCilGraph(MethodBase)

Returns CilGraph that represents this method

Declaration
public static CilGraph GetCilGraph(this MethodBase m)
Parameters
Type Name Description
System.Reflection.MethodBase m

Method for which to build CIL graph

Returns
Type Description
CilGraph

CIL graph object

GetCilText(MethodBase)

Returns this method's CIL code as string

Declaration
public static string GetCilText(this MethodBase m)
Parameters
Type Name Description
System.Reflection.MethodBase m

Method for which to retrieve CIL

Returns
Type Description
System.String

CIL code string

Remarks

Alias for MethodToText(MethodBase) method.

GetExecutingInstruction(StackFrame)

Gets an currently executing instruction corresponding to this stack frame

Declaration
public static CilInstruction GetExecutingInstruction(this StackFrame sf)
Parameters
Type Name Description
System.Diagnostics.StackFrame sf

A stack frame object

Returns
Type Description
CilInstruction

CIL instruction

GetInstructions(StackTrace)

Gets a repesentation of this stack trace as CIL instructions

Declaration
public static IEnumerable<CilInstruction> GetInstructions(this StackTrace trace)
Parameters
Type Name Description
System.Diagnostics.StackTrace trace

Stack trace object

Returns
Type Description
System.Collections.Generic.IEnumerable<CilInstruction>

A collection of CIL instructions

GetInstructions(MethodBase)

Retrieves all instructions from the method's body

Declaration
public static IEnumerable<CilInstruction> GetInstructions(this MethodBase m)
Parameters
Type Name Description
System.Reflection.MethodBase m

Source method

Returns
Type Description
System.Collections.Generic.IEnumerable<CilInstruction>

A collection of CIL instructions that form the body of this method

Exceptions
Type Condition
System.NotSupportedException

CilReader encountered unknown opcode

CilParserException

Failed to retrieve method body for the method

GetLastExecutedInstruction(StackFrame)

Gets a last executed instruction corresponding to this stack frame

Declaration
public static CilInstruction GetLastExecutedInstruction(this StackFrame sf)
Parameters
Type Name Description
System.Diagnostics.StackFrame sf

A stack frame object

Returns
Type Description
CilInstruction

CIL instruction

GetReferencedMembers(Assembly)

Gets all members referenced by the code of specified assembly

Declaration
public static IEnumerable<MemberInfo> GetReferencedMembers(this Assembly ass)
Parameters
Type Name Description
System.Reflection.Assembly ass

Assembly for which to retrieve referenced members

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

A collection of MemberInfo objects

Remarks

Referenced member is a member that appears as an operand of instruction in any of the assembly's methods.

GetReferencedMembers(Assembly, MemberCriteria)

Gets members referenced by the code of specified assembly that match specified criteria

Declaration
public static IEnumerable<MemberInfo> GetReferencedMembers(this Assembly ass, MemberCriteria flags)
Parameters
Type Name Description
System.Reflection.Assembly ass

Assembly for which to retrieve referenced members

MemberCriteria flags

A combination of bitwise flags that control what kind of members are retrieved

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

A collection of MemberInfo objects

Remarks

Referenced member is a member that appears as an operand of instruction in any of the assembly's methods.

GetReferencedMembers(MethodBase)

Gets all members (fields or methods) referenced by specified method

Declaration
public static IEnumerable<MemberInfo> GetReferencedMembers(this MethodBase mb)
Parameters
Type Name Description
System.Reflection.MethodBase mb

Method for which to retrieve referenced members

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

A collection of MemberInfo objects

Remarks

Referenced member is a member that appears as an operand of instruction in source method's body. For example, if the source method calls Foo method or creates delegate pointing to Foo, Foo is referenced by the source method.

Exceptions
Type Condition
System.NotSupportedException

CilReader encountered unknown opcode

CilParserException

Failed to retrieve method body for the method

GetReferencedMembers(MethodBase, MemberCriteria)

Gets members (fields or methods) referenced by specified method that match specified criteria

Declaration
public static IEnumerable<MemberInfo> GetReferencedMembers(this MethodBase mb, MemberCriteria flags)
Parameters
Type Name Description
System.Reflection.MethodBase mb

Method for which to retrieve referenced members

MemberCriteria flags

A combination of bitwise flags that control what kind of members are retrieved

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

A collection of MemberInfo objects

Remarks

Referenced member is a member that appears as an operand of instruction in source method's body. For example, if the source method calls Foo method or creates delegate pointing to Foo, Foo is referenced by the source method.

Exceptions
Type Condition
System.NotSupportedException

CilReader encountered unknown opcode

CilParserException

Failed to retrieve method body for the method

GetReferencedMembers(Type)

Gets all members referenced by the code of specified type

Declaration
public static IEnumerable<MemberInfo> GetReferencedMembers(this Type t)
Parameters
Type Name Description
System.Type t

Type for which to retrieve referenced memmbers

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

A collection of MemberInfo objects

Remarks

Referenced member is a member that appears as an operand of instruction in any of the type's methods.

GetReferencedMembers(Type, MemberCriteria)

Gets members referenced by the code of specified type that match specified criteria

Declaration
public static IEnumerable<MemberInfo> GetReferencedMembers(this Type t, MemberCriteria flags)
Parameters
Type Name Description
System.Type t

Type for which to retrieve referenced memmbers

MemberCriteria flags

A combination of bitwise flags that control what kind of members are retrieved

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

A collection of MemberInfo objects

Remarks

Referenced member is a member that appears as an operand of instruction in any of the type's methods.

GetReferencedMethods(Assembly)

Get all methods that are referenced by the code in the specified assembly

Declaration
public static IEnumerable<MethodBase> GetReferencedMethods(this Assembly ass)
Parameters
Type Name Description
System.Reflection.Assembly ass

Assembly for which to retrieve referenced methods

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MethodBase>

A collection of referenced methods

Remarks

Referenced member is a member that appears as an operand of instruction in any of the assembly's methods.

GetReferencedMethods(MethodBase)

Gets all methods that are referenced by this method

Declaration
public static IEnumerable<MethodBase> GetReferencedMethods(this MethodBase mb)
Parameters
Type Name Description
System.Reflection.MethodBase mb

Method for which to retrieve referenced methods

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MethodBase>

A collection of referenced methods

Remarks

Referenced member is a member that appears as an operand of instruction in source method's body. For example, if the source method calls Foo method or creates delegate pointing to Foo, Foo is referenced by the source method.

Exceptions
Type Condition
System.NotSupportedException

CilReader encountered unknown opcode

CilParserException

Failed to retrieve method body for the method

GetReferencedMethods(Type)

Get all methods that are referenced by the code of this type

Declaration
public static IEnumerable<MethodBase> GetReferencedMethods(this Type t)
Parameters
Type Name Description
System.Type t

Type for which to retrieve referenced methods

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Reflection.MethodBase>

A collection of referenced methods

Remarks

Referenced member is a member that appears as an operand of instruction in any of the type's methods.

PrintInstructions(StackTrace, TextWriter)

Prints this stack trace, represented as a CIL code, into the specified TextWriter

Declaration
public static void PrintInstructions(this StackTrace trace, TextWriter target = null)
Parameters
Type Name Description
System.Diagnostics.StackTrace trace

Source stack trace object

System.IO.TextWriter target

Target TextWriter object. If null or omitted, standard output will be used.

Back to top CIL Tools (published from sources in GitHub repository).
Generated by DocFX