Skip to content
Concord

Class Patcher

Namespace
Concord
Assembly
Concord.Orchestration.dll

The high-level entry point for applying Concord patches. Wraps the scan + compose + detour-apply pipeline so mod authors apply an assembly's PatchAttribute declarations, or a single explicit patch, with one call and revert by disposing the returned IPatchHandle.

public static class Patcher
Inheritance
Patcher
Inherited Members

Methods

Apply(Assembly)

Applies every PatchAttribute declaration in assembly, composing each as a detour and registering each declared field as an attached property. Idempotent: a repeated call with the same assembly returns the same handle without applying twice.

public static IPatchHandle Apply(Assembly assembly)

Parameters

assembly Assembly

The assembly whose declarations are applied.

Returns

IPatchHandle

A handle that reverts every applied detour when disposed.

For(MethodBase)

Creates a fluent PatchBuilder targeting the given method.

public static PatchBuilder For(MethodBase target)

Parameters

target MethodBase

The method to patch.

Returns

PatchBuilder

A PatchBuilder configured for target.

For(string, string)

Creates a fluent PatchBuilder targeting a method by name on a type resolved by name.

public static PatchBuilder For(string typeName, string method)

Parameters

typeName string

The full name of the type that declares the method.

method string

The name of the method to target.

Returns

PatchBuilder

A PatchBuilder configured for the resolved method.

Exceptions

ConcordDeclarationException

Thrown when the type or method is not found or is ambiguous.

For(string, string, Type[])

Creates a fluent PatchBuilder targeting a method by name on a type resolved by name, disambiguating by parameter types.

public static PatchBuilder For(string typeName, string method, Type[] parameterTypes)

Parameters

typeName string

The full name of the type that declares the method.

method string

The name of the method to target.

parameterTypes Type[]

The parameter types used to select a specific overload.

Returns

PatchBuilder

A PatchBuilder configured for the resolved method.

Exceptions

ConcordDeclarationException

Thrown when the type or method is not found.

For(Type, string)

Creates a fluent PatchBuilder targeting a method by name on the given type.

public static PatchBuilder For(Type type, string method)

Parameters

type Type

The type that declares the method.

method string

The name of the method to target.

Returns

PatchBuilder

A PatchBuilder configured for the resolved method.

Exceptions

ConcordDeclarationException

Thrown when the method is not found or is ambiguous.

For(Type, string, Type[])

Creates a fluent PatchBuilder targeting a method by name on the given type, disambiguating by parameter types.

public static PatchBuilder For(Type type, string method, Type[] parameterTypes)

Parameters

type Type

The type that declares the method.

method string

The name of the method to target.

parameterTypes Type[]

The parameter types used to select a specific overload.

Returns

PatchBuilder

A PatchBuilder configured for the resolved method.

Exceptions

ConcordDeclarationException

Thrown when the method is not found.

ForConstructor(Type, Type[])

Creates a fluent PatchBuilder targeting a specific instance constructor on type, selected by parameter types.

public static PatchBuilder ForConstructor(Type type, Type[] parameterTypes)

Parameters

type Type

The type that declares the constructor.

parameterTypes Type[]

The parameter types of the constructor to target. Pass an empty array to select the parameterless constructor. Only instance constructors are supported.

Returns

PatchBuilder

A PatchBuilder configured for the resolved constructor.

Exceptions

ConcordDeclarationException

Thrown when no matching instance constructor is found.

ForConstructor<T>(Type[])

Creates a fluent PatchBuilder targeting a specific instance constructor on T, selected by parameter types.

public static PatchBuilder ForConstructor<T>(Type[] parameterTypes)

Parameters

parameterTypes Type[]

The parameter types of the constructor to target. Pass an empty array to select the parameterless constructor. Only instance constructors are supported.

Returns

PatchBuilder

A PatchBuilder configured for the resolved constructor.

Type Parameters

T

The type that declares the constructor.

Exceptions

ConcordDeclarationException

Thrown when no matching instance constructor is found.

For<T>(string)

Creates a fluent PatchBuilder targeting a method by name on T.

public static PatchBuilder For<T>(string method)

Parameters

method string

The name of the method to target.

Returns

PatchBuilder

A PatchBuilder configured for the resolved method.

Type Parameters

T

The type that declares the method.

Exceptions

ConcordDeclarationException

Thrown when the method is not found or is ambiguous.

For<T>(string, Type[])

Creates a fluent PatchBuilder targeting a method by name on T, disambiguating by parameter types.

public static PatchBuilder For<T>(string method, Type[] parameterTypes)

Parameters

method string

The name of the method to target.

parameterTypes Type[]

The parameter types used to select a specific overload.

Returns

PatchBuilder

A PatchBuilder configured for the resolved method.

Type Parameters

T

The type that declares the method.

Exceptions

ConcordDeclarationException

Thrown when the method is not found.

Patch(MethodBase, MethodBase, At)

Applies a single explicit patch without scanning for attributes: composes injectionMethod onto target at the given position (Head, Return, Tail, Around, Transpiler, or TranspilerFinal).

public static IPatchHandle Patch(MethodBase target, MethodBase injectionMethod, At at)

Parameters

target MethodBase

The method to patch.

injectionMethod MethodBase

The injection method supplying the injected body.

at At

The injection position where the injection method runs relative to the target. Constant and Argument are not reachable through this method: use InjectAttribute for Constant, or build an Injection with an InjectAt.Invoke shifted Argument and apply it via PatchInjection(MethodBase, Injection) for Argument.

Returns

IPatchHandle

A handle that reverts the applied detour 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.

Exceptions

ConcordEmitException

Thrown with code CONC116 when at is Constant or Argument, neither of which this method can express.

PatchInjection(MethodBase, Injection)

Applies a single, already-constructed Injection at any position it can express (Head, Return with a specific index, Tail, Around, or Invoke), composing it directly rather than through the simplified At enum used by Patch(MethodBase, MethodBase, At).

public static IPatchHandle PatchInjection(MethodBase target, Injection injection)

Parameters

target MethodBase

The method to patch.

injection Injection

The injection to compose onto target.

Returns

IPatchHandle

A handle that reverts the applied detour 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.