Open sandboxFocus
  • TOC

Metalama Documentation

Getting started

Conceptual documentation

Commented examples

API documentation

Aspect API

Metalama.​Framework.​Advising

Metalama.​Framework.​Aspects

Metalama.​Framework.​Code

Metalama.​Framework.​Code.​Collections

Metalama.​Framework.​Code.​Comparers

Metalama.​Framework.​Code.​Declaration­Builders

Metalama.​Framework.​Code.​Invokers

Metalama.​Framework.​Code.​Syntax­Builders

Metalama.​Framework.​Code.​Types

Metalama.​Framework.​Diagnostics

Metalama.​Framework.​Eligibility

Metalama.​Framework.​Fabrics

Metalama.​Framework.​Metrics

Metalama.​Framework.​Options

Metalama.​Framework.​Project

Metalama.​Framework.​Run­Time

Metalama.​Framework.​Serialization

Metalama.​Framework.​Services

Metalama.​Framework.​Utilities

Extensions API

Patterns API

Flashtrace API

Introspection API

Advanced API

Post­Sharp API migration

  • Article

Constructor MethodTemplateSelector

MethodTemplateSelector(string, string?, string?, string?, string?, string?, bool, bool)

Initializes a new instance of the MethodTemplateSelector 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.

Declaration
public MethodTemplateSelector(string defaultTemplate, string? asyncTemplate = null, string? enumerableTemplate = null, string? enumeratorTemplate = null, string? asyncEnumerableTemplate = null, string? asyncEnumeratorTemplate = null, bool useAsyncTemplateForAnyAwaitable = false, bool useEnumerableTemplateForAnyEnumerable = false)
Parameters
Type Name Description
string defaultTemplate

Name of the template that must be applied if no other template is applicable. This parameter is required. See DefaultTemplate for details.

string asyncTemplate

Name of the template that must be applied to async methods, including async iterators unless specified otherwise. See AsyncTemplate for details.

string enumerableTemplate

Name of the template that must be applied to iterator methods returning an an IEnumerable<T> or IEnumerable. See EnumerableTemplate for details.

string enumeratorTemplate

Name of the template that must be applied to an iterator method returning an an IEnumerator<T> or IEnumerator. See EnumeratorTemplate for details.

string asyncEnumerableTemplate

Name of the template that must be applied to an async iterator method returning an IAsyncEnumerable. See AsyncEnumerableTemplate for details.

string asyncEnumeratorTemplate

Name of the template that must be applied to an async iterator method returning an IAsyncEnumerator. See AsyncEnumeratorTemplate for details.

bool useAsyncTemplateForAnyAwaitable

Indicates whether the AsyncTemplate must be applied to all methods returning an awaitable type (including IAsyncEnumerable and IAsyncEnumerator), instead of only to methods that have the async modifier. See UseAsyncTemplateForAnyAwaitable for details.

bool useEnumerableTemplateForAnyEnumerable

Indicates whether the EnumerableTemplate, EnumeratorTemplate, AsyncEnumerableTemplate, AsyncEnumeratorTemplate must be applied to all methods returning a compatible return type (if set to true), instead of only to methods using the yield statement. See UseEnumerableTemplateForAnyEnumerable for details.

Remarks

Note that this type has also an implicit conversion from string. If you only want to specify a default template, you can pass a string, without calling the constructor.

  • Navigation