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.
Namespace: Metalama.Extensions.Interceptors
Assembly: Metalama.Extensions.Interceptors.dll
Syntax
[CompileTime]
public static class InterceptionQueryExtensionsRemarks
Fabrics call these methods on their amender, and aspects can call them on Outbound.
Registration only records the interception. Sites are found later, in the source compilation, after all aspects and fabrics have run. Sites in code introduced by aspects are never intercepted.
At most one interceptor can apply to a site. When several registrations match the same site, each one is evaluated, and it is an error when more than one of them returns a result other than Skip().
The selected methods are the same for every scope declaration. A result that depends on the scope declaration is chosen per site with ForEachSite(Func<IMethodInterceptionSite, IMethodInterception>), which reads ScopeDeclaration and, for a tagged query, ScopeTag.
Only call sites written in the source code are intercepted. A call that the compiler, the runtime or a library makes on behalf of the
code is not intercepted, because no call exists at the site. For instance, ToString cannot be intercepted reliably: an interpolated
string, a string concatenation, Console.WriteLine( object ) and StringBuilder.Append( object ) call it inside the runtime.
The same applies to Equals and GetHashCode called by collections, to Dispose called by a using statement, and
to GetEnumerator called by a foreach statement.
Methods
| Name | Description |
|---|---|
| InterceptMethods<TScope>(IQuery<TScope>, Func<IMethodInterceptionBuilder, IMethodInterception>) | Registers the interception of the uses of methods in the declarations selected by a query, described by a delegate. |
| InterceptMethods<TScope, TTag>(ITaggedQuery<TScope, TTag>, Func<IMethodInterceptionBuilder, IMethodInterception>) | Registers the interception of the uses of methods in the declarations selected by a tagged query, described by a delegate. The tag of each declaration is available to ForEachSite(Func<IMethodInterceptionSite, IMethodInterception>) through ScopeTag. |