Skip to content
Concord

Class InjectAttribute

Namespace
Concord
Assembly
Concord.Emit.dll

Marks an injection method as an injection for a named target method.

[AttributeUsage(AttributeTargets.Method)]
public sealed class InjectAttribute : Attribute
Inheritance
InjectAttribute
Inherited Members

Constructors

InjectAttribute(At, string, uint, Type[]?)

Initializes a new injection declaration at the given position.

public InjectAttribute(At at, string method, uint by = 0, Type[]? parameterTypes = null)

Parameters

at At

The injection position: Head, Return, Tail, or Around.

method string

The target method name. Private names are validated by Concord tooling.

by uint

For Return, the 1-based occurrence of the return to target, or 0 for every return. Ignored for other positions.

parameterTypes Type[]

When non-null, selects a specific overload of method by parameter types, allowing ambiguous overloads to be disambiguated.

InjectAttribute(At, Type[]?)

Initializes a new injection declaration targeting the instance constructor of the patch target.

public InjectAttribute(At at, Type[]? parameterTypes = null)

Parameters

at At

The injection position: Head, Return, Tail, or Around.

parameterTypes Type[]

The parameter types of the constructor overload to target, or null to select the parameterless constructor. Only instance constructors are supported.

InjectAttribute(object, At, uint, Type[]?)

Initializes a new injection declaration targeting an inlined literal constant in the patch target's instance constructor.

public InjectAttribute(object constant, At at, uint by = 0, Type[]? parameterTypes = null)

Parameters

constant object

The literal to match. Supported kinds: int, long, float, double, string.

at At

The injection position. Must be Constant.

by uint

The 1-based occurrence of the constant to target, or 0 for every match.

parameterTypes Type[]

The parameter types of the constructor overload to target, or null to select the parameterless constructor. Only instance constructors are supported.

InjectAttribute(string, object, At, uint, Type[]?)

Initializes a new injection declaration targeting an inlined literal constant in the target body.

public InjectAttribute(string method, object constant, At at, uint by = 0, Type[]? parameterTypes = null)

Parameters

method string

The target method name. Private names are validated by Concord tooling.

constant object

The literal to match. Supported kinds: int, long, float, double, string.

at At

The injection position. Must be Constant.

by uint

The 1-based occurrence of the constant to target, or 0 for every match.

parameterTypes Type[]

When non-null, selects a specific overload of method by parameter types, allowing ambiguous overloads to be disambiguated.

InjectAttribute(string, Type, string, At, uint, Type[]?, Type[]?, uint)

Initializes a new injection declaration at an invoke-splice position, targeting a member access inside the target method.

[SuppressMessage("Major Code Smell", "S107", Justification = "Public attribute constructor; the parameters are the injection's authored call-site shape and cannot be bundled without breaking the API.")]
public InjectAttribute(string method, Type invokeDeclaringType, string invokeDeclaringMethod, At shift, uint by = 0, Type[]? targetParameterTypes = null, Type[]? invokeParameterTypes = null, uint arg = 0)

Parameters

method string

The target method name. Private names are validated by Concord tooling.

invokeDeclaringType Type

The type that declares the member access to match.

invokeDeclaringMethod string

The method, property, or field name to match.

shift At

Where the injection method runs relative to the matched access. Head and Tail support method calls, property calls, and field reads. Around and Argument support method and property calls only.

by uint

The 1-based occurrence of the matched access to target, or 0 for every match.

targetParameterTypes Type[]

When non-null, selects a specific overload of method on the patch target by parameter types.

invokeParameterTypes Type[]

For method or property calls, restricts matches by parameter types. Leave this null or empty when matching a field read.

arg uint

For Argument, the 1-based argument to rewrite, or 0 to infer by unique type match. Ignored for other shifts.

Properties

At

Gets the public injection-position value supplied to the declaration.

public At At { get; }

Property Value

At

Body

Gets or sets which body this injection attaches to when the target is an async or iterator method. Defaults to Declared, which patches the method as written - the compiler-generated stub that returns the Task or IEnumerable. Set StateMachine to reach the generated MoveNext instead. Ignored for targets that are neither async nor iterators.

public PatchBody Body { get; set; }

Property Value

PatchBody

Method

Gets the target method name this injection attaches to, or null when TargetsConstructor is true.

public string? Method { get; }

Property Value

string

ParameterTypes

Gets the parameter types used to disambiguate the target method overload or constructor overload, or null when no disambiguation is needed.

public Type[]? ParameterTypes { get; }

Property Value

Type[]

Priority

Gets or sets the ordering priority for this injection when multiple injections target the same method. Higher priority injections execute later (more outer) in tail chains. Defaults to 0.

public int Priority { get; set; }

Property Value

int

TargetsConstructor

Gets a value indicating whether this injection targets the declaring base type's instance constructor rather than a named method.

public bool TargetsConstructor { get; }

Property Value

bool