Class CilMethodBody
- Namespace
- AsmResolver.DotNet.Code.Cil
- Assembly
- AsmResolver.DotNet.dll
Represents a method body of a method defined in a .NET assembly, implemented using the Common Intermediate Language (CIL).
public class CilMethodBody : MethodBody
- Inheritance
-
CilMethodBody
- Inherited Members
Constructors
CilMethodBody(MethodDefinition)
Creates a new method body.
public CilMethodBody(MethodDefinition owner)
Parameters
owner
MethodDefinitionThe method that owns the method body.
Properties
BuildFlags
Gets or sets flags that alter the behaviour of the method body serializer for this specific method body.
public CilMethodBodyBuildFlags BuildFlags { get; set; }
Property Value
ComputeMaxStackOnBuild
Gets or sets a value indicating whether a .NET assembly builder should automatically compute and update the MaxStack property according to the contents of the method body.
public bool ComputeMaxStackOnBuild { get; set; }
Property Value
ExceptionHandlers
Gets a collection of regions protected by exception handlers, finally or faulting clauses defined in the method body.
public IList<CilExceptionHandler> ExceptionHandlers { get; }
Property Value
InitializeLocals
Gets or sets a value indicating whether all local variables should be initialized to zero by the runtime upon execution of the method body.
public bool InitializeLocals { get; set; }
Property Value
Instructions
Gets a collection of instructions to be executed in the method.
public CilInstructionCollection Instructions { get; }
Property Value
IsFat
Gets a value indicating whether the method body is considered fat. That is, it has at least one of the following properties
- The method is larger than 64 bytes.
- The method defines exception handlers.
- The method defines local variables.
- The method needs more than 8 values on the stack.
public bool IsFat { get; }
Property Value
LocalVariables
Gets a collection of local variables defined in the method body.
public CilLocalVariableCollection LocalVariables { get; }
Property Value
MaxStack
Gets or sets a value indicating the maximum amount of values stored onto the stack.
public int MaxStack { get; set; }
Property Value
VerifyLabelsOnBuild
Gets or sets a value indicating whether a .NET assembly builder should verify branch instructions and exception handler labels in this method body for validity.
public bool VerifyLabelsOnBuild { get; set; }
Property Value
Remarks
The value of this property will be ignored if ComputeMaxStackOnBuild is set to true
.
Methods
ComputeMaxStack()
Computes the maximum values pushed onto the stack by this method body.
public int ComputeMaxStack()
Returns
Remarks
This method will force the offsets of each instruction to be calculated.
Exceptions
- StackImbalanceException
Occurs when the method body will result in an unbalanced stack.
ComputeMaxStack(bool)
Computes the maximum values pushed onto the stack by this method body.
public int ComputeMaxStack(bool calculateOffsets)
Parameters
calculateOffsets
boolDetermines whether offsets should be calculated beforehand.
Returns
Exceptions
- StackImbalanceException
Occurs when the method body will result in an unbalanced stack.
FromRawMethodBody(ModuleReaderContext, MethodDefinition, CilRawMethodBody, ICilOperandResolver?)
Creates a CIL method body from a raw CIL method body.
public static CilMethodBody FromRawMethodBody(ModuleReaderContext context, MethodDefinition method, CilRawMethodBody rawBody, ICilOperandResolver? operandResolver = null)
Parameters
context
ModuleReaderContextThe reader context.
method
MethodDefinitionThe method that owns the method body.
rawBody
CilRawMethodBodyThe raw method body.
operandResolver
ICilOperandResolverThe object instance to use for resolving operands of an instruction in the method body.
Returns
- CilMethodBody
The method body.
VerifyLabels()
Verifies all branch targets and exception handler labels in the method body for validity.
public void VerifyLabels()
Remarks
This method will force the offsets of each instruction to be calculated.
Exceptions
- InvalidCilInstructionException
Occurs when one branch instruction in the method body is invalid.
- AggregateException
Occurs when multiple branch instructions in the method body are invalid.
VerifyLabels(bool)
Verifies all branch targets and exception handler labels in the method body for validity.
public void VerifyLabels(bool calculateOffsets)
Parameters
calculateOffsets
boolDetermines whether offsets should be calculated beforehand.
Exceptions
- InvalidCilInstructionException
Occurs when one branch instruction in the method body is invalid.
- AggregateException
Occurs when multiple branch instructions in the method body are invalid.