Open sandboxFocus

Method IntroduceProperty

IntroduceProperty(INamedType, string, IntroductionScope, OverrideStrategy, Action<IPropertyBuilder>?, object?)

Introduces a property to the target type, or overrides the implementation of an existing one, by specifying a property template.

Declaration
IIntroductionAdviceResult<IProperty> IntroduceProperty(INamedType targetType, string template, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IPropertyBuilder>? buildProperty = null, object? tags = null)
Parameters
Type Name Description
INamedType targetType

The type into which the property must be introduced.

string template

The name of the property in the aspect class that will be used as a template for the new property. This property must be annotated with TemplateAttribute. The type of this property can be either dynamic or any specific type. It is possible to dynamically change the type of the introduced property thanks to the IPropertyBuilder returned by this method.

IntroductionScope scope

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

OverrideStrategy whenExists

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

Action<IPropertyBuilder> buildProperty
object tags

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

Returns
Type Description
IIntroductionAdviceResult<IProperty>

An IPropertyBuilder that allows to dynamically change the name or type of the introduced property.

See Also

IntroduceProperty(INamedType, string, string?, string?, IntroductionScope, OverrideStrategy, Action<IPropertyBuilder>?, object?, object?)

Introduces a property to the target type, or overrides the implementation of an existing one, by specifying individual template methods for each accessor.

Declaration
IIntroductionAdviceResult<IProperty> IntroduceProperty(INamedType targetType, string name, string? getTemplate, string? setTemplate, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IPropertyBuilder>? buildProperty = null, object? args = null, object? tags = null)
Parameters
Type Name Description
INamedType targetType

The type into which the property must be introduced.

string name

Name of the introduced property.

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 property 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 field or property.

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 property 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 field or property.

IntroductionScope scope

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

OverrideStrategy whenExists

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

Action<IPropertyBuilder> buildProperty
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<IProperty>

An IPropertyBuilder that allows to dynamically change the name or type of the introduced property.

See Also