Open sandboxFocus
  • TOC

Metalama Documentation

Getting started

Video tutorials

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.​Code­Fixes

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

Metalama.​Framework.​Validation

Extensions API

Patterns API

Flashtrace API

Introspection API

Advanced API

Post­Sharp API migration

  • Article

Method IntroduceIndexer

IntroduceIndexer(IInterfaceImplementationAdviser, IType, string?, string?, IntroductionScope, OverrideStrategy, Action<IIndexerBuilder>?, object?, object?)

Introduces an indexer to the target type, or overrides the implementation of an existing one, by specifying individual template methods for each accessor. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IInterfaceImplementationAdviser adviser, IType indexType, string? getTemplate, string? setTemplate, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IIndexerBuilder>? buildIndexer = null, object? args = null, object? tags = null)
Parameters
Type Name Description
IInterfaceImplementationAdviser adviser

An IInterfaceImplementationAdviser.

IType indexType

The type of the initial index parameter.

string getTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null the introduced indexer should not have a getter. This method must be annotated with TemplateAttribute. The signature of this method must be T Get() where T is either dynamic or a type compatible with the type of the indexer.

string setTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null if the introduced indexer should not have a setter. This method must be annotated with TemplateAttribute. The signature of this method must be void Set(T value where T is either dynamic or a type compatible with the type of the indexer.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced indexer. The default scope depends on the scope of the template accessors. If the accessors are static, the introduced indexer is static. However, if the template accessors are non-static, then the introduced indexer copies of the scope of the target declaration of the aspect.

OverrideStrategy whenExists

Determines the implementation strategy when a indexer of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IIndexerBuilder> buildIndexer
object args

An object (typically of anonymous type) whose properties map to parameters or type parameters of the template methods.

object tags

An optional opaque object of anonymous type passed to the template method and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIndexerBuilder that allows to dynamically change the name or type of the introduced indexer.

See Also

IntroduceIndexer(IInterfaceImplementationAdviser, Type, string?, string?, IntroductionScope, OverrideStrategy, Action<IIndexerBuilder>?, object?, object?)

Introduces an indexer to the target type, or overrides the implementation of an existing one, by specifying individual template methods for each accessor. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IInterfaceImplementationAdviser adviser, Type indexType, string? getTemplate, string? setTemplate, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IIndexerBuilder>? buildIndexer = null, object? args = null, object? tags = null)
Parameters
Type Name Description
IInterfaceImplementationAdviser adviser

An IInterfaceImplementationAdviser.

Type indexType

The type of the initial index parameter.

string getTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null the introduced indexer should not have a getter. This method must be annotated with TemplateAttribute. The signature of this method must be T Get() where T is either dynamic or a type compatible with the type of the indexer.

string setTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null if the introduced indexer should not have a setter. This method must be annotated with TemplateAttribute. The signature of this method must be void Set(T value where T is either dynamic or a type compatible with the type of the indexer.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced indexer. The default scope depends on the scope of the template accessors. If the accessors are static, the introduced indexer is static. However, if the template accessors are non-static, then the introduced indexer copies of the scope of the target declaration of the aspect.

OverrideStrategy whenExists

Determines the implementation strategy when a indexer of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IIndexerBuilder> buildIndexer
object args

An object (typically of anonymous type) whose properties map to parameters or type parameters of the template methods.

object tags

An optional opaque object of anonymous type passed to the template method and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIndexerBuilder that allows to dynamically change the name or type of the introduced indexer.

See Also

IntroduceIndexer(IInterfaceImplementationAdviser, IReadOnlyList<(IType Type, string Name)>, string?, string?, IntroductionScope, OverrideStrategy, Action<IIndexerBuilder>?, object?, object?)

Introduces an indexer to the target type, or overrides the implementation of an existing one, by specifying individual template methods for each accessor. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IInterfaceImplementationAdviser adviser, IReadOnlyList<(IType Type, string Name)> indices, string? getTemplate, string? setTemplate, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IIndexerBuilder>? buildIndexer = null, object? args = null, object? tags = null)
Parameters
Type Name Description
IInterfaceImplementationAdviser adviser

An IInterfaceImplementationAdviser.

IReadOnlyList<(IType Type, string Name)> indices

The types and names of the index parameters.

string getTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null the introduced indexer should not have a getter. This method must be annotated with TemplateAttribute. The signature of this method must be T Get() where T is either dynamic or a type compatible with the type of the indexer.

string setTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null if the introduced indexer should not have a setter. This method must be annotated with TemplateAttribute. The signature of this method must be void Set(T value where T is either dynamic or a type compatible with the type of the indexer.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced indexer. The default scope depends on the scope of the template accessors. If the accessors are static, the introduced indexer is static. However, if the template accessors are non-static, then the introduced indexer copies of the scope of the target declaration of the aspect.

OverrideStrategy whenExists

Determines the implementation strategy when a indexer of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IIndexerBuilder> buildIndexer
object args

An object (typically of anonymous type) whose properties map to parameters or type parameters of the template methods.

object tags

An optional opaque object of anonymous type passed to the template method and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIndexerBuilder that allows to dynamically change the name or type of the introduced indexer.

See Also

IntroduceIndexer(IInterfaceImplementationAdviser, IReadOnlyList<(Type Type, string Name)>, string?, string?, IntroductionScope, OverrideStrategy, Action<IIndexerBuilder>?, object?, object?)

Introduces an indexer to the target type, or overrides the implementation of an existing one, by specifying individual template methods for each accessor. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IInterfaceImplementationAdviser adviser, IReadOnlyList<(Type Type, string Name)> indices, string? getTemplate, string? setTemplate, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IIndexerBuilder>? buildIndexer = null, object? args = null, object? tags = null)
Parameters
Type Name Description
IInterfaceImplementationAdviser adviser

An IInterfaceImplementationAdviser.

IReadOnlyList<(Type Type, string Name)> indices

The types and names of the index parameters.

string getTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null the introduced indexer should not have a getter. This method must be annotated with TemplateAttribute. The signature of this method must be T Get() where T is either dynamic or a type compatible with the type of the indexer.

string setTemplate

The name of the method of the aspect class whose type and implementation will be used as a template for the getter, or null if the introduced indexer should not have a setter. This method must be annotated with TemplateAttribute. The signature of this method must be void Set(T value where T is either dynamic or a type compatible with the type of the indexer.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced indexer. The default scope depends on the scope of the template accessors. If the accessors are static, the introduced indexer is static. However, if the template accessors are non-static, then the introduced indexer copies of the scope of the target declaration of the aspect.

OverrideStrategy whenExists

Determines the implementation strategy when a indexer of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IIndexerBuilder> buildIndexer
object args

An object (typically of anonymous type) whose properties map to parameters or type parameters of the template methods.

object tags

An optional opaque object of anonymous type passed to the template method and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIndexerBuilder that allows to dynamically change the name or type of the introduced indexer.

See Also