Open sandboxFocus

Struct GetterTemplateSelector

Specifies which T# templates to use when overriding property or field getters, enabling automatic selection of specialized templates for iterator getters.

Namespace: Metalama.Framework.Advising
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public readonly struct GetterTemplateSelector
Remarks

When overriding field or property accessors with OverrideAccessors(IAdviser<IFieldOrProperty>, in GetterTemplateSelector, string?, object?, object?), you can provide different templates for properties that return IEnumerable<T> or IEnumerator<T>. Template selection depends on the UseEnumerableTemplateForAnyEnumerable flag.

Default behavior (UseEnumerableTemplateForAnyEnumerable is false): Templates are selected based on how the getter is implemented:

When UseEnumerableTemplateForAnyEnumerable is true: Iterator templates are selected based on the property's return type (e.g., IEnumerable<T>, IEnumerator<T>), regardless of whether the getter uses yield statements.

This type has an implicit conversion from string, so if you only need a default template, you can pass the template name directly without constructing a GetterTemplateSelector.

Constructors

Name Description
GetterTemplateSelector(string, string?, string?, bool)

Initializes a new instance of the GetterTemplateSelector struct by specifying the name of the template methods to be applied. The named passed to this constructor must be the name of methods of the current aspect class, and these methods must be annotated with the TemplateAttribute custom attribute. You can define several templates by passing a value to optional parameters. The appropriate template will be automatically selected according to the method to which the advice is applied. If several templates are eligible for a method, the template that is the last in the list of parameters is selected.

Properties

Name Description
DefaultTemplate

Gets the name of the template that must be applied if no other template is applicable. This property is required if you want to override the getter.

EnumerableTemplate

Gets the name of the template that must be applied to iterator getters returning an IEnumerable<T> or IEnumerable.

EnumeratorTemplate

Gets the name of the template that must be applied to iterator getters returning an IEnumerator<T> or IEnumerator.

UseEnumerableTemplateForAnyEnumerable

Gets a value indicating whether the EnumerableTemplate or EnumeratorTemplate must be applied to all methods returning compatible return type, instead of only to methods using the yield statement.

Operators

Name Description
implicit operator GetterTemplateSelector(string?)

Converts a string to a new instance of the GetterTemplateSelector where the DefaultTemplate property is set to this string.

See Also