Class InstructionSpec
- Namespace
- AsmLocator
- Assembly
- AsmLocator.dll
Describes constraints for a CIL instruction. An empty specification matches every instruction and can be used as a one-instruction wildcard inside a pattern.
public sealed record InstructionSpec : IEquatable<InstructionSpec>
- Inheritance
-
InstructionSpec
- Implements
- Inherited Members
Constructors
InstructionSpec()
public InstructionSpec()
Properties
AnyInstruction
A specification that matches any single instruction, useful as a pattern wildcard.
public static InstructionSpec AnyInstruction { get; }
Property Value
Code
The exact CIL opcode code.
public CilCode? Code { get; init; }
Property Value
Mnemonic
The instruction mnemonic matcher, for example call, ldstr, or ldc.i4*.
public StringMatcher? Mnemonic { get; init; }
Property Value
Offset
The instruction offset to match. Offsets can be stale after edits until offsets are recalculated.
public int? Offset { get; init; }
Property Value
- int?
Operand
The operand matcher. Operand values are converted to text by DescribeOperand(CilInstruction).
For example, use Console::WriteLine to match a method descriptor.
public StringMatcher? Operand { get; init; }
Property Value
Where
An optional custom predicate applied after the built-in constraints.
public Func<CilInstruction, bool>? Where { get; init; }
Property Value
Methods
Call(StringMatcher)
Matches call and callvirt instructions, but not calli.
public static InstructionSpec Call(StringMatcher method)
Parameters
methodStringMatcherA matcher for the called method's full name.
Returns
- InstructionSpec
An instruction specification for direct and virtual method calls.
DescribeOperand(CilInstruction)
Converts common operand types to the textual representation used by Operand matching:
member and type descriptors use FullName; strings use their literal value; locals use V_n;
parameters use their names; labels use IL_XXXX; switch labels are comma-separated; other values use invariant conversion.
public static string? DescribeOperand(CilInstruction instruction)
Parameters
instructionCilInstructionThe candidate CIL instruction.
Returns
Equals(InstructionSpec?)
public bool Equals(InstructionSpec? other)
Parameters
otherInstructionSpec
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetHashCode()
public override int GetHashCode()
Returns
LdStr(StringMatcher)
Matches ldstr instructions whose string operand matches the supplied matcher.
public static InstructionSpec LdStr(StringMatcher text)
Parameters
textStringMatcherA matcher for the string literal.
Returns
- InstructionSpec
The instruction specification.
Matches(CilInstruction)
Returns whether the supplied candidate satisfies all constraints configured in this specification.
public bool Matches(CilInstruction instruction)
Parameters
instructionCilInstructionThe candidate CIL instruction.
Returns
NewObj(StringMatcher)
Matches newobj instructions whose constructor operand matches the supplied matcher.
public static InstructionSpec NewObj(StringMatcher ctor)
Parameters
ctorStringMatcherA matcher for the constructor descriptor.
Returns
- InstructionSpec
The instruction specification.
Op(CilOpCode, StringMatcher?)
Creates an instruction specification for an exact opcode and optional operand matcher.
public static InstructionSpec Op(CilOpCode opCode, StringMatcher? operand = null)
Parameters
opCodeCilOpCodeThe CIL opcode to match.
operandStringMatcherAn optional matcher for the instruction operand.
Returns
- InstructionSpec
A new specification with the described constraints.
ToString()
Returns a readable representation of this object.
public override string ToString()
Returns
- string
A readable description.
WithMnemonic(StringMatcher, StringMatcher?)
Creates an instruction specification for a mnemonic and optional operand matcher.
public static InstructionSpec WithMnemonic(StringMatcher mnemonic, StringMatcher? operand = null)
Parameters
mnemonicStringMatcherThe instruction mnemonic matcher.
operandStringMatcherAn optional matcher for the instruction operand.
Returns
- InstructionSpec
A new specification with the described constraints.
Operators
operator ==(InstructionSpec?, InstructionSpec?)
public static bool operator ==(InstructionSpec? left, InstructionSpec? right)
Parameters
leftInstructionSpecrightInstructionSpec
Returns
operator !=(InstructionSpec?, InstructionSpec?)
public static bool operator !=(InstructionSpec? left, InstructionSpec? right)
Parameters
leftInstructionSpecrightInstructionSpec