Skip to content
Concord

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

injectionMethod MethodInfo

The 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

parameterTypes Type[]

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

selected PatchBody

The 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

injectionMethod MethodInfo

The 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

parameterTypes Type[]

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

at At

The 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.Argument for Argument.

injectionMethod MethodInfo

The method that supplies the injected body.

Returns

PatchBuilder

This builder, for chaining.

Exceptions

ConcordEmitException

Thrown with code CONC116 when at is 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

at At

The 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.Argument for Argument.

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The 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 CONC116 when at is 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

callSiteType Type

The type that declares the member access to splice.

callSiteMethod string

The method, property, or field name to splice.

injectionMethod MethodInfo

The method that supplies the injected body.

shift At

Where the injection method runs relative to the matched access. Around supports method and property calls only.

by uint

The 1-based occurrence to target, or 0 for 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

callSiteType Type

The type that declares the member access to splice.

callSiteMethod string

The method, property, or field name to splice.

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

shift At

Where the injection method runs relative to the matched access. Around supports method and property calls only.

by uint

The 1-based occurrence to target, or 0 for 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

callSiteType Type

The type that declares the call-site method to splice.

callSiteMethod string

The name of the method to splice.

callSiteParameterTypes Type[]

The parameter types of the call-site overload to target. Only call sites whose parameters match this array are considered.

injectionMethod MethodInfo

The method that supplies the injected body.

shift At

Where the injection method runs relative to the matched call: Head before, Tail after, or Around wrapping it.

by uint

The 1-based occurrence to target, or 0 for 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

callSiteType Type

The type that declares the call-site method to splice.

callSiteMethod string

The name of the method to splice.

callSiteParameterTypes Type[]

The parameter types of the call-site overload to target. Only call sites whose parameters match this array are considered.

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

shift At

Where the injection method runs relative to the matched call: Head before, Tail after, or Around wrapping it.

by uint

The 1-based occurrence to target, or 0 for 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

constructedType Type

The type whose construction to splice.

injectionMethod MethodInfo

The method that supplies the injected body.

shift At

Where the injection method runs relative to the construction.

by uint

The 1-based occurrence to target, or 0 for 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

constructedType Type

The type whose construction to splice.

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

shift At

Where the injection method runs relative to the construction.

by uint

The 1-based occurrence to target, or 0 for 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

constructedType Type

The type whose construction to splice.

constructorParameterTypes Type[]

The parameter types of the constructor overload to target.

injectionMethod MethodInfo

The method that supplies the injected body.

shift At

Where the injection method runs relative to the construction.

by uint

The 1-based occurrence to target, or 0 for 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

constructedType Type

The type whose construction to splice.

constructorParameterTypes Type[]

The parameter types of the constructor overload to target.

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

shift At

Where the injection method runs relative to the construction.

by uint

The 1-based occurrence to target, or 0 for 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

injectionMethod MethodInfo

The method that supplies the injected body.

by uint

The 1-based occurrence of the return to target, or 0 for 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

by uint

The 1-based occurrence of the return to target, or 0 for 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

by uint

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

parameterTypes Type[]

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

range SliceRange

The 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

injectionMethod MethodInfo

The 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

parameterTypes Type[]

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

injectionMethod MethodInfo

The static method that rewrites the instruction stream.

final bool

false 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

injectionMethodType Type

The type that declares the injection method.

injectionMethodName string

The name of the injection method.

final bool

Whether to rewrite the composed wrapper rather than the original body.

Returns

PatchBuilder

This builder, for chaining.