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
atAtmethodstringThe target method name. Private names are validated by Concord tooling.
byuintFor Return, the 1-based occurrence of the return to target, or
0for every return. Ignored for other positions.parameterTypesType[]When non-null, selects a specific overload of
methodby 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
atAtparameterTypesType[]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
constantobjectThe literal to match. Supported kinds: int, long, float, double, string.
atAtThe injection position. Must be Constant.
byuintThe 1-based occurrence of the constant to target, or
0for every match.parameterTypesType[]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
methodstringThe target method name. Private names are validated by Concord tooling.
constantobjectThe literal to match. Supported kinds: int, long, float, double, string.
atAtThe injection position. Must be Constant.
byuintThe 1-based occurrence of the constant to target, or
0for every match.parameterTypesType[]When non-null, selects a specific overload of
methodby 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
methodstringThe target method name. Private names are validated by Concord tooling.
invokeDeclaringTypeTypeThe type that declares the member access to match.
invokeDeclaringMethodstringThe method, property, or field name to match.
shiftAtWhere 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.
byuintThe 1-based occurrence of the matched access to target, or
0for every match.targetParameterTypesType[]When non-null, selects a specific overload of
methodon the patch target by parameter types.invokeParameterTypesType[]For method or property calls, restricts matches by parameter types. Leave this null or empty when matching a field read.
arguintFor Argument, the 1-based argument to rewrite, or
0to 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
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
Method
Gets the target method name this injection attaches to, or null when TargetsConstructor is true.
public string? Method { get; }
Property Value
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
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; }