Open sandboxFocus

Method IntroduceAttribute

IntroduceAttribute(IDeclaration, IAttributeData, OverrideStrategy)

Adds a custom attribute to a given declaration.

Declaration
IIntroductionAdviceResult<IAttribute> IntroduceAttribute(IDeclaration targetDeclaration, IAttributeData attribute, OverrideStrategy whenExists = OverrideStrategy.Default)
Parameters
Type Name Description
IDeclaration targetDeclaration

The declaration to which the custom attribute should be added.

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>