Open sandboxFocus

Method IntroduceAttribute

IntroduceAttribute(IAdviser<IDeclaration>, IAttributeData, OverrideStrategy)

Adds a custom attribute to a given declaration. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IIntroductionAdviceResult<IAttribute> IntroduceAttribute(this IAdviser<IDeclaration> adviser, IAttributeData attribute, OverrideStrategy whenExists = OverrideStrategy.Default)
Parameters
Type Name Description
IAdviser<IDeclaration> adviser

An adviser for a declaration.

IAttributeData attribute

The custom attribute to be added. It can be an existing IAttribute, or you can use AttributeConstruction to specify a new attribute.

OverrideStrategy whenExists

Specifies the strategy to follow when an attribute of the same type already exists on the target declaration. Fail will fail the compilation with an error and is the default strategy. Ignore will silently ignore the introduction. Override will remove all previous instances and replace them by the new one. New will add the new instance regardless.

Returns
Type Description
IIntroductionAdviceResult<IAttribute>