This namespace allows you to intercept the calls to methods of any assembly, and to redirect them to an existing method or to a method generated from a T# template.
Conceptual documentation
Refer to Interceptors.
Overview
Aspects and fabrics register interceptors with the InterceptMethods extension methods of InterceptionAdviserExtensions and InterceptionQueryExtensions. The argument is a delegate that describes the interception as a chain of immutable values, in this order:
- IMethodInterceptionBuilder sets the calling code, and selects the type that declares the intercepted methods.
- ITypeSelection and ITypeFilterSelection select the methods.
- IMethodSelection filters the methods, and chooses the interceptor through IMethodResultFactory, or decides for each call site with ForEachSite.
- IExistingMethodInterception or ITemplateInterception sets the options of the interceptor.
A template reads the description of the interception through the meta.Interception property, of type IInterceptionInfo.
The ExcludeInterceptorsAttribute attribute and the InterceptorConfigurationExtensions extension methods exclude code from interception.
Class diagram
classDiagram
class IMethodInterceptionBuilder {
IncludingNestedTypes()
ExcludingLambdas()
Type()
Types()
}
class ITypeFilterSelection {
Methods()
}
class ITypeSelection {
AllMethods()
}
class IMethodResultFactory {
RedirectToExistingMethod()
RedirectToSynthesizedMethod()
}
class IMethodSelection {
Where()
IncludingInterfaceImplementations()
ExcludingOverrides()
ForEachSite()
}
class IMethodInterceptionSite {
Skip()
}
class IMethodInterception
class IExistingMethodInterception {
WithArgs()
}
class ITemplateInterception {
WithArgs()
WithTags()
WithTemplateProvider()
PlaceInStaticClass()
PlaceInCallingType()
PlaceInType()
WithGranularity()
Configure()
}
IMethodInterceptionBuilder --> ITypeSelection : Type()
IMethodInterceptionBuilder --> ITypeFilterSelection : Types()
ITypeSelection --|> ITypeFilterSelection
ITypeFilterSelection --> IMethodSelection : Methods()
IMethodSelection --|> IMethodResultFactory
IMethodInterceptionSite --|> IMethodResultFactory
IMethodResultFactory --> IExistingMethodInterception
IMethodResultFactory --> ITemplateInterception
IExistingMethodInterception --|> IMethodInterception
ITemplateInterception --|> IMethodInterception
Classes
ExcludeInterceptorsAttribute
Excludes the code of the declaration from interception, or includes it again: when excluded, no site inside the declaration, or inside a declaration that it contains, is presented to any interceptor registration.
InterceptionAdviserExtensions
Provides extension methods that register interceptors from an aspect or a type fabric. The scope is the target of the adviser: a compilation, a namespace, a type or a member.
InterceptionMetaExtensions
Extends meta with the information about interceptions.
InterceptionQueryExtensions
Provides extension methods that register interceptors through a query. Each declaration selected by the query is a scope: the uses of the selected methods located in its code are intercepted.
InterceptorConfigurationExtensions
Extension methods that configure interception from a fabric, for the declarations that a query selects.
Structs
InterceptorReceiverEligibility
Describes whether the receiver of a call can or must be mapped to the this of the generated interceptor method, that is, whether
ReceiverMapping can or must be This. The
ReceiverEligibility property gives it.
InvocationArgument
Describes the argument passed to one parameter at a call site.
Interfaces
ICaller
Describes the code that contains a site: the member, the kind of code and the function.
IConfiguredTemplateInterception
A method interception whose calls are redirected to a method synthesized from a template, after the first call of
Configure(Action<IInterceptorMethodBuilder>). It is a complete interception, which the delegate given to InterceptMethods or to
ForEachSite(Func<IMethodInterceptionSite, IMethodInterception>) can return.
IExistingMethodInterception
A method interception whose calls are redirected to an existing method, created by
RedirectToExistingMethod(IMethod). It is a complete interception, which the delegate given to
InterceptMethods or to ForEachSite(Func<IMethodInterceptionSite, IMethodInterception>) can return.
IInterceptionContext
The base interface of the contexts of a call site. It describes one site. IMethodInterceptionSite and Context implement or expose it.
IInterceptionInfo
Describes the interception that a template implements. A template reads it through the meta.Interception property.
IInterceptorMethodBuilder
Lets the delegate given to Configure(Action<IInterceptorMethodBuilder>) shape the interceptor method that a template generates for a method call.
IInvocationReceiver
Describes the receiver written at a site: the object on which the method is called or from which the method group is taken.
IMethodInterception
A complete description of a method interception, or of the interception of one call site. The delegate given to InterceptMethods
returns it, and so does the delegate given to ForEachSite(Func<IMethodInterceptionSite, IMethodInterception>).
IMethodInterceptionBuilder
The first stage of the description of a method interception, which the delegate given to InterceptMethods receives. It sets where
the call sites are, and then selects the type that declares the intercepted methods.
IMethodInterceptionContext
Describes one use of a method that a method registration selects: a call, or a method group converted to a delegate, added to or removed from an event, or converted to a function pointer.
IMethodInterceptionInfo
Describes the interception of a method call that a template implements, as given by the Method property.
IMethodInterceptionSite
One call site in the delegate given to ForEachSite(Func<IMethodInterceptionSite, IMethodInterception>). It describes the site, through the members of IMethodInterceptionContext, and creates the result of the site.
IMethodResultFactory
Chooses how the selected calls are intercepted: redirected to an existing method, or redirected to a method synthesized from a template. It is the base of IMethodSelection, for a result that applies to every call site, and of IMethodInterceptionSite, for the result of one call site.
IMethodSelection
The stage of a method interception at which the intercepted methods are selected. It filters the methods, decides whether the calls bound to their overrides and to their interface implementations match, and then chooses how the calls are intercepted.
ITemplateInterception
A method interception whose calls are redirected to a method synthesized from a template. Its methods set the options of the synthesized
method. It is a complete interception, which the delegate given to InterceptMethods or to
ForEachSite(Func<IMethodInterceptionSite, IMethodInterception>) can return.
ITypeFilterSelection
The stage of a method interception at which the types that declare the intercepted methods are selected by a predicate. The methods must be given by name.
ITypeSelection
The stage of a method interception at which one type that declares the intercepted methods is selected.
Enums
CallerKind
Kinds of code that immediately contain a site.
InterceptionKind
Kinds of interception that a template implements, as given by Kind.
InterceptorGranularity
Declares what the template of a synthesized interceptor depends on, and therefore which call sites share one synthesized method. Set it with the WithGranularity(InterceptorGranularity) method.
InterceptorReceiverMapping
Kinds of mapping of the receiver of an intercepted call to the parameters of a generated interceptor method.
InvocationArgumentKind
Kinds of argument passed to one parameter at a call site.
InvocationDispatchKind
Kinds of dispatch of an intercepted call.
InvocationReceiverKind
Kinds of receiver written at a call site.
MethodUseKind
Kinds of use of a method at a site.
NonInterceptableReason
Reasons why a site that matches a registration cannot be intercepted in this version.