Table of Contents

Class ILFunction

Namespace
ICSharpCode.Decompiler.IL
Assembly
ICSharpCode.Decompiler.dll

A container of IL blocks.

public sealed class ILFunction : ILInstruction
Inheritance
ILFunction
Inherited Members

Constructors

ILFunction(IMethod, int, GenericContext, ILInstruction, ILFunctionKind)

Constructs a new ILFunction from the given metadata and with the given ILAst body.

public ILFunction(IMethod method, int codeSize, GenericContext genericContext, ILInstruction body, ILFunctionKind kind = ILFunctionKind.TopLevelFunction)

Parameters

method IMethod
codeSize int
genericContext GenericContext
body ILInstruction
kind ILFunctionKind

Remarks

Use ILReader to create ILAst.

Fields

AsyncDebugInfo

public AsyncDebugInfo AsyncDebugInfo

Field Value

AsyncDebugInfo

AsyncReturnType

Return element type -- if the async method returns Task{T}, this field stores T. If the async method returns Task or void, this field stores void.

public IType? AsyncReturnType

Field Value

IType

BodySlot

public static readonly SlotInfo BodySlot

Field Value

SlotInfo

CodeSize

Size of the IL code in this function. Note: after async/await transform, this is the code size of the MoveNext function.

public int CodeSize

Field Value

int

DelegateType

If this is an expression tree or delegate, returns the expression tree type Expression{T} or T. T is the delegate type that matches the signature of this method. Otherwise this must be null.

public IType? DelegateType

Field Value

IType

GenericContext

Gets the generic context of this function.

public readonly GenericContext GenericContext

Field Value

GenericContext

IsIterator

Gets whether this function is a decompiled iterator (is using yield). This flag gets set by the YieldReturnDecompiler.

If set, the 'return' instruction has the semantics of 'yield break;' instead of a normal return.

public bool IsIterator

Field Value

bool

LocalFunctionsSlot

public static readonly SlotInfo LocalFunctionsSlot

Field Value

SlotInfo

Method

Gets the method definition from metadata. May be null for functions that were not constructed from metadata, e.g., expression trees.

public readonly IMethod? Method

Field Value

IMethod

MoveNextMethod

If this function is an iterator/async, this field stores the compiler-generated MoveNext() method.

public IMethod? MoveNextMethod

Field Value

IMethod

Name

Gets the name of this function, usually this returns the name from metadata.

For local functions: This is the name that is used to declare and use the function. It may not conflict with the names of local variables of ancestor functions and may be overwritten by the AssignVariableNames step.

For top-level functions, delegates and expressions trees modifying this usually has no effect, as the name should not be used in the final AST construction.

public string? Name

Field Value

string

Parameters

List of parameters of this function.

public readonly IReadOnlyList<IParameter> Parameters

Field Value

IReadOnlyList<IParameter>

ReturnType

Return type of this function.

public readonly IType ReturnType

Field Value

IType

StateMachineCompiledWithLegacyVisualBasic

Gets whether the YieldReturnDecompiler determined that the Legacy VB compiler was used to compile this function.

public bool StateMachineCompiledWithLegacyVisualBasic

Field Value

bool

StateMachineCompiledWithMono

Gets whether the YieldReturnDecompiler determined that the Mono C# compiler was used to compile this function.

public bool StateMachineCompiledWithMono

Field Value

bool

Variables

List of ILVariables used in this function.

public readonly ILVariableCollection Variables

Field Value

ILVariableCollection

Properties

Body

public ILInstruction Body { get; set; }

Property Value

ILInstruction

CapturedVariables

Gets the set of captured variables by this ILFunction.

public HashSet<ILVariable> CapturedVariables { get; }

Property Value

HashSet<ILVariable>

Remarks

This is populated by the TransformDisplayClassUsage step.

DeclarationScope

Gets the scope in which the local function is declared. Returns null, if this is not a local function.

public BlockContainer? DeclarationScope { get; }

Property Value

BlockContainer

DirectFlags

Gets the flags for this instruction only, without considering the child instructions.

public override InstructionFlags DirectFlags { get; }

Property Value

InstructionFlags

IsAsync

Gets whether this function is async. This flag gets set by the AsyncAwaitDecompiler.

public bool IsAsync { get; }

Property Value

bool

Kind

Gets which kind of function this is.

public ILFunctionKind Kind { get; }

Property Value

ILFunctionKind

LocalFunctions

public InstructionCollection<ILFunction> LocalFunctions { get; }

Property Value

InstructionCollection<ILFunction>

ResultType

Gets the stack type of the value produced by this instruction.

public override StackType ResultType { get; }

Property Value

StackType

SequencePointCandidates

List of candidate locations for sequence points. Includes any offset where the stack is empty, nop instructions, and the instruction following a call instruction

public List<int>? SequencePointCandidates { get; set; }

Property Value

List<int>

Warnings

List of warnings of ILReader.

public List<string> Warnings { get; }

Property Value

List<string>

Methods

AcceptVisitor(ILVisitor)

Calls the Visit*-method on the visitor corresponding to the concrete type of this instruction.

public override void AcceptVisitor(ILVisitor visitor)

Parameters

visitor ILVisitor

AcceptVisitor<T>(ILVisitor<T>)

Calls the Visit*-method on the visitor corresponding to the concrete type of this instruction.

public override T AcceptVisitor<T>(ILVisitor<T> visitor)

Parameters

visitor ILVisitor<T>

Returns

T

Type Parameters

T

AcceptVisitor<C, T>(ILVisitor<C, T>, C)

Calls the Visit*-method on the visitor corresponding to the concrete type of this instruction.

public override T AcceptVisitor<C, T>(ILVisitor<C, T> visitor, C context)

Parameters

visitor ILVisitor<C, T>
context C

Returns

T

Type Parameters

C
T

Clone()

public override sealed ILInstruction Clone()

Returns

ILInstruction

ComputeFlags()

protected override InstructionFlags ComputeFlags()

Returns

InstructionFlags

GetChild(int)

protected override sealed ILInstruction GetChild(int index)

Parameters

index int

Returns

ILInstruction

GetChildCount()

protected override sealed int GetChildCount()

Returns

int

GetChildSlot(int)

protected override sealed SlotInfo GetChildSlot(int index)

Parameters

index int

Returns

SlotInfo

PerformMatch(ILInstruction?, ref Match)

protected override bool PerformMatch(ILInstruction? other, ref Match match)

Parameters

other ILInstruction
match Match

Returns

bool

RegisterVariable(VariableKind, IType, string?)

public ILVariable RegisterVariable(VariableKind kind, IType type, string? name = null)

Parameters

kind VariableKind
type IType
name string

Returns

ILVariable

RunTransforms(IEnumerable<IILTransform>, ILTransformContext)

Apply a list of transforms to this function.

public void RunTransforms(IEnumerable<IILTransform> transforms, ILTransformContext context)

Parameters

transforms IEnumerable<IILTransform>
context ILTransformContext

SetChild(int, ILInstruction)

protected override sealed void SetChild(int index, ILInstruction value)

Parameters

index int
value ILInstruction

WriteTo(ITextOutput, ILAstWritingOptions)

Writes the ILAst to the text output.

public override void WriteTo(ITextOutput output, ILAstWritingOptions options)

Parameters

output ITextOutput
options ILAstWritingOptions