Class PatchBuilder
- Namespace
- Concord
- Assembly
- Concord.Orchestration.dll
A fluent builder that accumulates one or more injections for a single target method and applies them all in one Apply() call. Create instances via For(MethodBase) and its overloads.
public sealed class PatchBuilder
- Inheritance
-
PatchBuilder
- Inherited Members
Methods
Apply()
Composes and applies all recorded injections onto the target method in a single operation, returning a handle that reverts them all when disposed.
public IPatchHandle Apply()
Returns
- IPatchHandle
A handle that reverts all applied detours when disposed.
Remarks
The returned handle is retained in a static registry, so the detour stays applied even when the caller discards the handle. Dispose the handle to revert the detour and release it from the registry.
Around(MethodInfo)
Records an around-call injection using the supplied injection method.
public PatchBuilder Around(MethodInfo injectionMethod)
Parameters
injectionMethodMethodInfoThe method that supplies the injected body.
Returns
- PatchBuilder
This builder, for chaining.
Around(Type, string)
Records an around-call injection, resolving the injection method by name on
injectionMethodType.
public PatchBuilder Around(Type injectionMethodType, string injectionMethodName)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
Returns
- PatchBuilder
This builder, for chaining.
Around(Type, string, Type[])
Records an around-call injection, resolving the injection method by name on
injectionMethodType, disambiguating by parameter types.
public PatchBuilder Around(Type injectionMethodType, string injectionMethodName, Type[] parameterTypes)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
parameterTypesType[]The parameter types used to select a specific overload.
Returns
- PatchBuilder
This builder, for chaining.
Body(PatchBody)
Selects which body the injections recorded after this call attach to when the target is an async or iterator method. Injections already recorded keep the value in effect when they were recorded, so one builder can mix both.
public PatchBuilder Body(PatchBody selected)
Parameters
selectedPatchBodyThe body to select.
Returns
- PatchBuilder
This builder, for chaining.
Head(MethodInfo)
Records a head-of-method injection using the supplied injection method.
public PatchBuilder Head(MethodInfo injectionMethod)
Parameters
injectionMethodMethodInfoThe method that supplies the injected body.
Returns
- PatchBuilder
This builder, for chaining.
Head(Type, string)
Records a head-of-method injection, resolving the injection method by name on
injectionMethodType.
public PatchBuilder Head(Type injectionMethodType, string injectionMethodName)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
Returns
- PatchBuilder
This builder, for chaining.
Head(Type, string, Type[])
Records a head-of-method injection, resolving the injection method by name on
injectionMethodType, disambiguating by parameter types.
public PatchBuilder Head(Type injectionMethodType, string injectionMethodName, Type[] parameterTypes)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
parameterTypesType[]The parameter types used to select a specific overload.
Returns
- PatchBuilder
This builder, for chaining.
Inject(At, MethodInfo)
Records a head, tail, return, around, or transpiler injection at the given position using the supplied injection method. For an invoke-splice injection use Invoke(Type, string, MethodInfo, At, uint).
public PatchBuilder Inject(At at, MethodInfo injectionMethod)
Parameters
atAtThe injection position. Return targets every return. Constant and Argument are not reachable through this overload: use InjectAttribute for Constant, and Invoke(Type, string, MethodInfo, At, uint) with
shift: At.Argumentfor Argument.injectionMethodMethodInfoThe method that supplies the injected body.
Returns
- PatchBuilder
This builder, for chaining.
Exceptions
- ConcordEmitException
Thrown with code
CONC116whenatis Constant or Argument, neither of which this overload can express.
Inject(At, Type, string)
Records a head, tail, return, around, or transpiler injection at the given position, resolving the
injection method by name on injectionMethodType.
public PatchBuilder Inject(At at, Type injectionMethodType, string injectionMethodName)
Parameters
atAtThe injection position. Return targets every return. Constant and Argument are not reachable through this overload: use InjectAttribute for Constant, and Invoke(Type, string, MethodInfo, At, uint) with
shift: At.Argumentfor Argument.injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
Returns
- PatchBuilder
This builder, for chaining.
Exceptions
- ArgumentException
Thrown when the injection method is not found.
- ConcordEmitException
Thrown with code
CONC116whenatis Constant or Argument, neither of which this overload can express.
Invoke(Type, string, MethodInfo, At, uint)
Records an invoke-splice injection on a named member access inside the target, using the supplied injection method. Head and Tail also support field reads.
public PatchBuilder Invoke(Type callSiteType, string callSiteMethod, MethodInfo injectionMethod, At shift, uint by = 0)
Parameters
callSiteTypeTypeThe type that declares the member access to splice.
callSiteMethodstringThe method, property, or field name to splice.
injectionMethodMethodInfoThe method that supplies the injected body.
shiftAtWhere the injection method runs relative to the matched access. Around supports method and property calls only.
byuintThe 1-based occurrence to target, or
0for every matching access.
Returns
- PatchBuilder
This builder, for chaining.
Invoke(Type, string, Type, string, At, uint)
Records an invoke-splice injection on a named member access inside the target, resolving the injection method by name. Head and Tail also support field reads.
public PatchBuilder Invoke(Type callSiteType, string callSiteMethod, Type injectionMethodType, string injectionMethodName, At shift, uint by = 0)
Parameters
callSiteTypeTypeThe type that declares the member access to splice.
callSiteMethodstringThe method, property, or field name to splice.
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
shiftAtWhere the injection method runs relative to the matched access. Around supports method and property calls only.
byuintThe 1-based occurrence to target, or
0for every matching access.
Returns
- PatchBuilder
This builder, for chaining.
Invoke(Type, string, Type[], MethodInfo, At, uint)
Records an invoke-splice injection on a method or property call inside the target, using the supplied injection method and disambiguating the call site by parameter types.
public PatchBuilder Invoke(Type callSiteType, string callSiteMethod, Type[] callSiteParameterTypes, MethodInfo injectionMethod, At shift, uint by = 0)
Parameters
callSiteTypeTypeThe type that declares the call-site method to splice.
callSiteMethodstringThe name of the method to splice.
callSiteParameterTypesType[]The parameter types of the call-site overload to target. Only call sites whose parameters match this array are considered.
injectionMethodMethodInfoThe method that supplies the injected body.
shiftAtWhere the injection method runs relative to the matched call: Head before, Tail after, or Around wrapping it.
byuintThe 1-based occurrence to target, or
0for every matching call.
Returns
- PatchBuilder
This builder, for chaining.
Invoke(Type, string, Type[], Type, string, At, uint)
Records an invoke-splice injection on a method or property call inside the target, resolving the injection method by name and disambiguating the call site by parameter types.
public PatchBuilder Invoke(Type callSiteType, string callSiteMethod, Type[] callSiteParameterTypes, Type injectionMethodType, string injectionMethodName, At shift, uint by = 0)
Parameters
callSiteTypeTypeThe type that declares the call-site method to splice.
callSiteMethodstringThe name of the method to splice.
callSiteParameterTypesType[]The parameter types of the call-site overload to target. Only call sites whose parameters match this array are considered.
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
shiftAtWhere the injection method runs relative to the matched call: Head before, Tail after, or Around wrapping it.
byuintThe 1-based occurrence to target, or
0for every matching call.
Returns
- PatchBuilder
This builder, for chaining.
NewObj(Type, MethodInfo, At, uint)
Records a construction-site injection on the supplied constructed type, using the supplied injection method.
public PatchBuilder NewObj(Type constructedType, MethodInfo injectionMethod, At shift, uint by = 0)
Parameters
constructedTypeTypeThe type whose construction to splice.
injectionMethodMethodInfoThe method that supplies the injected body.
shiftAtWhere the injection method runs relative to the construction.
byuintThe 1-based occurrence to target, or
0for every matching construction.
Returns
- PatchBuilder
This builder, for chaining.
NewObj(Type, Type, string, At, uint)
Records a construction-site injection on the supplied constructed type, resolving the injection method by name.
public PatchBuilder NewObj(Type constructedType, Type injectionMethodType, string injectionMethodName, At shift, uint by = 0)
Parameters
constructedTypeTypeThe type whose construction to splice.
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
shiftAtWhere the injection method runs relative to the construction.
byuintThe 1-based occurrence to target, or
0for every matching construction.
Returns
- PatchBuilder
This builder, for chaining.
NewObj(Type, Type[], MethodInfo, At, uint)
Records a construction-site injection on the supplied constructed type, using the supplied injection method and disambiguating the constructor by parameter types.
public PatchBuilder NewObj(Type constructedType, Type[] constructorParameterTypes, MethodInfo injectionMethod, At shift, uint by = 0)
Parameters
constructedTypeTypeThe type whose construction to splice.
constructorParameterTypesType[]The parameter types of the constructor overload to target.
injectionMethodMethodInfoThe method that supplies the injected body.
shiftAtWhere the injection method runs relative to the construction.
byuintThe 1-based occurrence to target, or
0for every matching construction.
Returns
- PatchBuilder
This builder, for chaining.
NewObj(Type, Type[], Type, string, At, uint)
Records a construction-site injection on the supplied constructed type, resolving the injection method by name and disambiguating the constructor by parameter types.
public PatchBuilder NewObj(Type constructedType, Type[] constructorParameterTypes, Type injectionMethodType, string injectionMethodName, At shift, uint by = 0)
Parameters
constructedTypeTypeThe type whose construction to splice.
constructorParameterTypesType[]The parameter types of the constructor overload to target.
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
shiftAtWhere the injection method runs relative to the construction.
byuintThe 1-based occurrence to target, or
0for every matching construction.
Returns
- PatchBuilder
This builder, for chaining.
Return(MethodInfo, uint)
Records a return-site injection that runs before each return in the target, using the supplied injection method.
public PatchBuilder Return(MethodInfo injectionMethod, uint by = 0)
Parameters
injectionMethodMethodInfoThe method that supplies the injected body.
byuintThe 1-based occurrence of the return to target, or
0for every return.
Returns
- PatchBuilder
This builder, for chaining.
Return(Type, string, uint)
Records a return-site injection that runs before each return in the target, resolving the injection method
by name on injectionMethodType.
public PatchBuilder Return(Type injectionMethodType, string injectionMethodName, uint by = 0)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
byuintThe 1-based occurrence of the return to target, or
0for every return.
Returns
- PatchBuilder
This builder, for chaining.
Return(Type, string, uint, Type[])
Records a return-site injection that runs before each return in the target, resolving the injection method
by name on injectionMethodType, disambiguating by parameter types.
public PatchBuilder Return(Type injectionMethodType, string injectionMethodName, uint by, Type[] parameterTypes)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
byuintThe 1-based occurrence of the return to target, or
0for every return.parameterTypesType[]The parameter types used to select a specific overload.
Returns
- PatchBuilder
This builder, for chaining.
Slice(SliceRange)
Bounds the most recently recorded invoke or construction injection to the supplied range.
public PatchBuilder Slice(SliceRange range)
Parameters
rangeSliceRangeThe range that limits call-site matching and occurrence counting.
Returns
- PatchBuilder
This builder, for chaining.
Exceptions
- ConcordDeclarationException
Thrown when no injection has been recorded, or the most recently recorded injection is not an invoke or construction injection.
Tail(MethodInfo)
Records a tail injection that runs once at the end of the target, using the supplied injection method.
public PatchBuilder Tail(MethodInfo injectionMethod)
Parameters
injectionMethodMethodInfoThe method that supplies the injected body.
Returns
- PatchBuilder
This builder, for chaining.
Tail(Type, string)
Records a tail injection that runs once at the end of the target, resolving the injection method by name on
injectionMethodType.
public PatchBuilder Tail(Type injectionMethodType, string injectionMethodName)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
Returns
- PatchBuilder
This builder, for chaining.
Tail(Type, string, Type[])
Records a tail injection that runs once at the end of the target, resolving the injection method by name on
injectionMethodType, disambiguating by parameter types.
public PatchBuilder Tail(Type injectionMethodType, string injectionMethodName, Type[] parameterTypes)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
parameterTypesType[]The parameter types used to select a specific overload.
Returns
- PatchBuilder
This builder, for chaining.
Transpiler(MethodInfo, bool)
Records a raw IL transpiler injection using the supplied injection method.
public PatchBuilder Transpiler(MethodInfo injectionMethod, bool final = false)
Parameters
injectionMethodMethodInfoThe static method that rewrites the instruction stream.
finalboolfalse rewrites the original body before declarative injections compose onto it. true rewrites the fully composed wrapper, which has no stability guarantee.
Returns
- PatchBuilder
This builder, for chaining.
Transpiler(Type, string, bool)
Records a raw IL transpiler injection, resolving the injection method by name on
injectionMethodType.
public PatchBuilder Transpiler(Type injectionMethodType, string injectionMethodName, bool final = false)
Parameters
injectionMethodTypeTypeThe type that declares the injection method.
injectionMethodNamestringThe name of the injection method.
finalboolWhether to rewrite the composed wrapper rather than the original body.
Returns
- PatchBuilder
This builder, for chaining.