Class ILVariable
- Namespace
- ICSharpCode.Decompiler.IL
- Assembly
- ICSharpCode.Decompiler.dll
public class ILVariable
- Inheritance
-
ILVariable
- Inherited Members
Constructors
ILVariable(VariableKind, IType, StackType, int?)
public ILVariable(VariableKind kind, IType type, StackType stackType, int? index = null)
Parameters
kind
VariableKindtype
ITypestackType
StackTypeindex
int?
ILVariable(VariableKind, IType, int?)
public ILVariable(VariableKind kind, IType type, int? index = null)
Parameters
kind
VariableKindtype
ITypeindex
int?
Fields
StackType
public readonly StackType StackType
Field Value
StateMachineField
The field which was converted to a local variable. Set when the variable is from a 'yield return' or 'async' state machine.
public IField? StateMachineField
Field Value
Properties
AddressCount
Number of ldloca instructions referencing this variable.
public int AddressCount { get; }
Property Value
Remarks
This variable is automatically updated when adding/removing ldloca instructions from the ILAst.
AddressInstructions
List of ldloca instructions referencing this variable.
public IReadOnlyList<LdLoca> AddressInstructions { get; }
Property Value
Remarks
This list is automatically updated when adding/removing ldloca instructions from the ILAst.
CaptureScope
Gets the block container in which this variable is captured. For captured variables declared inside the loop, the capture scope is the BlockContainer of the loop. For captured variables declared outside of the loop, the capture scope is the BlockContainer of the parent function.
public BlockContainer? CaptureScope { get; }
Property Value
Remarks
This property returns null for variables that are not captured.
Function
Gets the function in which this variable is declared.
public ILFunction? Function { get; }
Property Value
Remarks
This property is set automatically when the variable is added to the ILFunction.Variables
collection.
HasGeneratedName
public bool HasGeneratedName { get; set; }
Property Value
HasInitialValue
[Obsolete("Use 'UsesInitialValue' instead.")]
public bool HasInitialValue { get; set; }
Property Value
HasNullCheck
Gets/sets whether a parameter has an auto-generated null check, i.e., the !! modifier. Returns false for all variables except parameters.
public bool HasNullCheck { get; set; }
Property Value
Index
The index of the local variable or parameter (depending on Kind)
For VariableKinds with "Local" in the name:
- if non-null, the Index refers to the LocalVariableSignature.
- index may be null for variables that used to be fields (captured by lambda/async) For Parameters, the Index refers to the method's list of parameters. The special "this" parameter has index -1. For ExceptionStackSlot, the index is the IL offset of the exception handler. For other kinds, the index has no meaning, and is usually null.
public int? Index { get; }
Property Value
- int?
IndexInFunction
Gets the index of this variable within the Function.Variables
collection.
public int IndexInFunction { get; }
Property Value
Remarks
This property is set automatically when the variable is added to the VariableScope.Variables
collection.
It may change if an item with a lower index is removed from the collection.
InitialValueIsInitialized
Gets/Sets whether the variable's initial value is initialized.
This is always true
for parameters (incl. this
).
Normal variables have an initial value if the function uses ".locals init".
public bool InitialValueIsInitialized { get; set; }
Property Value
IsDead
Gets whether the variable is dead - unused.
public bool IsDead { get; }
Property Value
IsRefReadOnly
This variable is either a C# 7 'in' parameter or must be declared as 'ref readonly'.
public bool IsRefReadOnly { get; }
Property Value
IsSingleDefinition
Gets whether the variable is in SSA form: There is exactly 1 store, and every load sees the value from that store.
public bool IsSingleDefinition { get; }
Property Value
Remarks
Note: the single store is not necessary a store instruction, it might also be the use of the implicit initial value. For example: for parameters, IsSingleDefinition will only return true if the parameter is never assigned to within the function.
Kind
public VariableKind Kind { get; }
Property Value
LoadCount
Number of ldloc instructions referencing this variable.
public int LoadCount { get; }
Property Value
Remarks
This variable is automatically updated when adding/removing ldloc instructions from the ILAst.
LoadInstructions
List of ldloc instructions referencing this variable.
public IReadOnlyList<LdLoc> LoadInstructions { get; }
Property Value
Remarks
This list is automatically updated when adding/removing ldloc instructions from the ILAst.
Name
public string? Name { get; set; }
Property Value
StoreCount
Number of store instructions referencing this variable, plus 1 if HasInitialValue.
Stores are:
public int StoreCount { get; }
Property Value
Remarks
This variable is automatically updated when adding/removing stores instructions from the ILAst.
StoreInstructions
List of store instructions referencing this variable.
Stores are:
public IReadOnlyList<IStoreInstruction> StoreInstructions { get; }
Property Value
Remarks
This list is automatically updated when adding/removing stores instructions from the ILAst.
Type
public IType Type { get; }
Property Value
UsesInitialValue
Gets/Sets whether the initial value of the variable is used.
This is always true
for parameters (incl. this
).
Normal variables use the initial value, if no explicit initialization is done.
public bool UsesInitialValue { get; set; }
Property Value
Remarks
The following table shows the relationship between InitialValueIsInitialized and UsesInitialValue.
InitialValueIsInitialized | UsesInitialValue | Meaning |
---|---|---|
true | true | This variable's initial value is zero-initialized (.locals init ) and the initial value is used.
From C#'s point of view a the value default(T) is assigned at the site of declaration. |
true | false | This variable's initial value is zero-initialized (.locals init ) and the initial value is not used.
From C#'s point of view no implicit initialization occurs, because the code assigns a value
explicitly, before the variable is first read. |
false | true | This variable's initial value is uninitialized (.locals without init ) and the
initial value is used.
From C#'s point of view a call to
is generated after the declaration. |
false | false | This variable's initial value is uninitialized (.locals without init ) and the
initial value is not used.
From C#'s point of view no implicit initialization occurs, because the code assigns a value
explicitly, before the variable is first read. |
Methods
ToString()
public override string? ToString()