Open sandboxFocus

Method IntroduceIndexer

IntroduceIndexer(IAdviser<INamedType>, 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.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IAdviser<INamedType> 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
IAdviser<INamedType> adviser

An adviser for a named type.

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 if 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 setter, 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 the scope of the target declaration of the aspect.

OverrideStrategy whenExists

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

Action<IIndexerBuilder> buildIndexer

An optional delegate that modifies the IIndexerBuilder representing the introduced indexer.

object args

An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details.

object tags

An optional object (typically of anonymous type) passed to the template and accessible via meta.Tags. See Sharing state with adviceSharing state with advice for details.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIntroductionAdviceResult<T> exposing the introduced or overriding IIndexer.

Remarks

This method introduces an indexer with a single index parameter. Use the overload that accepts IReadOnlyList<(IType, string)> for indexers with multiple index parameters.

Use With<TNewDeclaration>(TNewDeclaration) to introduce the indexer into a different type than the current target.

See Also

IntroduceIndexer(IAdviser<INamedType>, 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.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IAdviser<INamedType> 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
IAdviser<INamedType> adviser

An adviser for a named type.

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 if 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 setter, 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 the scope of the target declaration of the aspect.

OverrideStrategy whenExists

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

Action<IIndexerBuilder> buildIndexer

An optional delegate that modifies the IIndexerBuilder representing the introduced indexer.

object args

An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details.

object tags

An optional object (typically of anonymous type) passed to the template and accessible via meta.Tags. See Sharing state with adviceSharing state with advice for details.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIntroductionAdviceResult<T> exposing the introduced or overriding IIndexer.

Remarks

This overload is identical to the IType-based overload, but accepts a Type parameter for convenience when working with reflection types. This introduces an indexer with a single index parameter.

Use With<TNewDeclaration>(TNewDeclaration) to introduce the indexer into a different type than the current target.

See Also

IntroduceIndexer(IAdviser<INamedType>, 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.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IAdviser<INamedType> 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
IAdviser<INamedType> adviser

An adviser for a named type.

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 if 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 setter, 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 the scope of the target declaration of the aspect.

OverrideStrategy whenExists

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

Action<IIndexerBuilder> buildIndexer

An optional delegate that modifies the IIndexerBuilder representing the introduced indexer.

object args

An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details.

object tags

An optional object (typically of anonymous type) passed to the template and accessible via meta.Tags. See Sharing state with adviceSharing state with advice for details.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIntroductionAdviceResult<T> exposing the introduced or overriding IIndexer.

Remarks

This method allows you to introduce indexers with multiple index parameters (e.g., this[int row, int column]). For indexers with a single parameter, you can use the simpler overload that accepts a single IType.

Use With<TNewDeclaration>(TNewDeclaration) to introduce the indexer into a different type than the current target.

See Also

IntroduceIndexer(IAdviser<INamedType>, 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.

Declaration
public static IIntroductionAdviceResult<IIndexer> IntroduceIndexer(this IAdviser<INamedType> 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
IAdviser<INamedType> adviser

An adviser for a named type.

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 if 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 setter, 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 the scope of the target declaration of the aspect.

OverrideStrategy whenExists

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

Action<IIndexerBuilder> buildIndexer

An optional delegate that modifies the IIndexerBuilder representing the introduced indexer.

object args

An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details.

object tags

An optional object (typically of anonymous type) passed to the template and accessible via meta.Tags. See Sharing state with adviceSharing state with advice for details.

Returns
Type Description
IIntroductionAdviceResult<IIndexer>

An IIntroductionAdviceResult<T> exposing the introduced or overriding IIndexer.

Remarks

This overload is identical to the IReadOnlyList<(IType, string)>-based overload, but accepts Type parameters for convenience when working with reflection types. This method allows indexers with multiple index parameters.

Use With<TNewDeclaration>(TNewDeclaration) to introduce the indexer into a different type than the current target.

See Also