Open sandboxFocus

Enum 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.

Namespace: Metalama.Extensions.Interceptors
Assembly: Metalama.Extensions.Interceptors.dll
Syntax
[CompileTime]
[Flags]
public enum InterceptorGranularity
Remarks

The enumeration has two independent dimensions:

  • The site levels Type, Member and CallSite nest: each level includes the coarser ones. Their values are cumulative, so the combination of two levels is the finer one, and granularity.HasFlag( InterceptorGranularity.Type ) means "at least Type". A granularity without a site level is global: the template does not depend on the call site.
  • Owner can be combined with any site level, for instance InterceptorGranularity.Member | InterceptorGranularity.Owner.

The default granularity is Global. The engine does not detect what the template depends on: neither the tags, nor the aspect state, nor the fields of the aspect. When several call sites share a generated method, the template is expanded once, for the representative call site, which is the first in the order of the file paths and the positions, and with the aspect instance that registered the interceptor for that call site. This is the same rule as when several instances of an aspect target the same declaration, where the BuildAspect method must summarize them. A template that depends on the state of its aspect instance must therefore include Owner in the granularity. The tags of the result are compared by value, so the call sites whose results have different tags never share a method.

The template reads the context through the meta.Interception property. A property that requires a finer granularity than the granularity of the interceptor throws an InvalidOperationException that names the granularity to set.

Fields

Name Description
CallSite

The template can read the call site through the meta.Interception.Caller and meta.Interception.Source properties, and it can read the calling member and the calling type. Each call site has its own method.

Default

The default granularity, which is Global.

Global

The template depends neither on the call site nor on the aspect instance that registered the interceptor. The method is shared by all the call sites that have the same template, arguments, tags, placement and signature. This is the default granularity.

Member

The template can read the calling member through the meta.Interception.CallingMember property, and the calling type. The method is shared by the call sites of the same member.

Owner

The template can depend on the aspect instance or the fabric that registered the interceptor, and on its aspect state. The method is shared only by the call sites of the same registration.

Type

The template can read the calling type through the meta.Interception.CallingType property. The method is shared by the call sites of the same type.