Show / Hide Table of Contents

Class CilInstruction

Represents CIL instruction, a main structural element of the method body which consists of operation code and operand.

Inheritance
System.Object
CilInstruction
Inherited Members
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
Assembly: CilTools.BytecodeAnalysis.dll
Syntax
public abstract class CilInstruction
Remarks

To retrieve a collection of CIL instructions for the specified method, use methods of CilReader class.

Constructors

CilInstruction(OpCode, UInt32, UInt32, MethodBase)

Creates a new CilInstruction object initialized with specified field values (infrastructure)

Declaration
protected CilInstruction(OpCode opc, uint byteoffset = 0U, uint ordinalnum = 0U, MethodBase mb = null)
Parameters
Type Name Description
System.Reflection.Emit.OpCode opc

Opcode

System.UInt32 byteoffset

Byte offset

System.UInt32 ordinalnum

Ordinal number

System.Reflection.MethodBase mb

Owning method

Properties

ByteOffset

Gets a byte offset of this instruction from the beginning of the method body

Declaration
public uint ByteOffset { get; }
Property Value
Type Description
System.UInt32

Code

Gets opcode of this instruction as a numerical value

Declaration
public short Code { get; }
Property Value
Type Description
System.Int16

Method

Gets a reference to a method which this instruction belongs to

Declaration
public MethodBase Method { get; }
Property Value
Type Description
System.Reflection.MethodBase

Name

Gets a name of this instruction

Declaration
public string Name { get; }
Property Value
Type Description
System.String

OpCode

Gets the operation code (opcode) of this instruction

Declaration
public OpCode OpCode { get; }
Property Value
Type Description
System.Reflection.Emit.OpCode

Operand

Gets the operand object of this instruction

Declaration
public abstract object Operand { get; }
Property Value
Type Description
System.Object

OperandSize

Gets the size, in bytes, of this instruction's operand

Declaration
public abstract uint OperandSize { get; }
Property Value
Type Description
System.UInt32

OperandType

Gets this instruction's operand type, or null if there's no operand

Declaration
public abstract Type OperandType { get; }
Property Value
Type Description
System.Type

OrdinalNumber

Gets ordinal number of the place this instruction takes in method body, starting from one.

Declaration
public uint OrdinalNumber { get; }
Property Value
Type Description
System.UInt32

ReferencedLocal

Gets the information about local variable referenced by this instruction, if applicable

Declaration
public abstract LocalVariableInfo ReferencedLocal { get; }
Property Value
Type Description
System.Reflection.LocalVariableInfo

ReferencedMember

Gets a member (type, field or method) referenced by this instruction, if applicable

Declaration
public abstract MemberInfo ReferencedMember { get; }
Property Value
Type Description
System.Reflection.MemberInfo

ReferencedParameter

Gets the information about method parameter referenced by this instruction, if applicable

Declaration
public abstract ParameterInfo ReferencedParameter { get; }
Property Value
Type Description
System.Reflection.ParameterInfo

ReferencedSignature

Gets a signature referenced by this instruction, if applicable

Declaration
public abstract Signature ReferencedSignature { get; }
Property Value
Type Description
Signature

ReferencedString

Gets a string literal referenced by this instruction, if applicable

Declaration
public abstract string ReferencedString { get; }
Property Value
Type Description
System.String

ReferencedType

Gets a type referenced by this instruction, if applicable

Declaration
public Type ReferencedType { get; }
Property Value
Type Description
System.Type

TotalSize

Gets total size, in bytes, that this instruction occupies in the method body

Declaration
public uint TotalSize { get; }
Property Value
Type Description
System.UInt32

Methods

Create(OpCode, UInt32, UInt32, MethodBase)

Creates new CilInstruction object for instruction without operand

Declaration
public static CilInstruction Create(OpCode opc, uint byteoffset = 0U, uint ordinalnum = 0U, MethodBase mb = null)
Parameters
Type Name Description
System.Reflection.Emit.OpCode opc

Instruction opcode

System.UInt32 byteoffset

Byte offset

System.UInt32 ordinalnum

Ordinal number

System.Reflection.MethodBase mb

Owning method

Returns
Type Description
CilInstruction

Create<T>(OpCode, T, UInt32, UInt32, UInt32, MethodBase)

Creates new CilInstruction object for instruction with operand

Declaration
public static CilInstruction Create<T>(OpCode opc, T operand, uint operandsize, uint byteoffset = 0U, uint ordinalnum = 0U, MethodBase mb = null)
Parameters
Type Name Description
System.Reflection.Emit.OpCode opc

Instruction opcode

T operand

Operand value

System.UInt32 operandsize

Operand size in bytes

System.UInt32 byteoffset

Byte offset

System.UInt32 ordinalnum

Ordinal number

System.Reflection.MethodBase mb

Owning method

Returns
Type Description
CilInstruction
Type Parameters
Name Description
T

Operand type

CreateEmptyInstruction(MethodBase)

Creates new CilInstruction object that represents an empty instruction

Declaration
public static CilInstruction CreateEmptyInstruction(MethodBase mb)
Parameters
Type Name Description
System.Reflection.MethodBase mb

Owning method

Returns
Type Description
CilInstruction

Empty CilInstruction object

EmitTo(ILGenerator)

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

Declaration
public void EmitTo(ILGenerator ilg)
Parameters
Type Name Description
System.Reflection.Emit.ILGenerator ilg

Target IL generator.

OperandToString(TextWriter)

Writes the text representation of this instruction's operand into the specified TextWriter

Declaration
public abstract void OperandToString(TextWriter target)
Parameters
Type Name Description
System.IO.TextWriter target

The destination TextWriter

Parse(String)

Converts CIL instruction textual representation into the corresponding CilInstruction object

Declaration
public static CilInstruction Parse(string str)
Parameters
Type Name Description
System.String str

The line of CIL code representing instruction

Returns
Type Description
CilInstruction

The instruction object for the specified string, or null when the specified string does not contain the instruction or the instruction can't be parsed

Exceptions
Type Condition
System.ArgumentNullException

str is null

System.ArgumentException

str is an empty string

System.NotSupportedException

The instruction name is invalid

ToString()

Returns a text representation of this instruction as a line of CIL code

Declaration
public override string ToString()
Returns
Type Description
System.String

String containing text representation of this instruction

Overrides
System.Object.ToString()

ToSyntax()

Gets the instruction syntax

Declaration
public IEnumerable<SyntaxNode> ToSyntax()
Returns
Type Description
System.Collections.Generic.IEnumerable<SyntaxNode>

The collection of syntax nodes that represent this instruction syntax

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