Open sandboxFocus
  • TOC

Metalama Documentation

Getting started

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.​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

Extensions API

Patterns API

Flashtrace API

Introspection API

Advanced API

Post­Sharp API migration

  • Article

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>
  • Navigation