Metalama 1.0 / / Metalama Documentation / Aspect API / Metalama.​Framework.​Code­Fixes / Code­Fix­Factory / Add­Attribute

Method AddAttribute

AddAttribute(IDeclaration, Type, String)

Creates a CodeFix that adds a custom attribute to a declaration, without constructor or named arguments, by specifying the reflection Type of the attribute.

Declaration
public static CodeFix AddAttribute(IDeclaration targetDeclaration, Type attributeType, string title = null)
Parameters
Type Name Description
IDeclaration targetDeclaration

The declaration to which the attribute must be added.

Type attributeType

The type of the attribute.

String title

An optional title of the CodeFix, displayed to the user in the light bulb or refactoring menu. When not specified, the title is generated from the other parameters.

Returns
Type Description
CodeFix

AddAttribute(IDeclaration, INamedType, String)

Creates a CodeFix that adds a custom attribute to a declaration, without constructor or named arguments, by specifying the INamedType of the attribute.

Declaration
public static CodeFix AddAttribute(IDeclaration targetDeclaration, INamedType attributeType, string title = null)
Parameters
Type Name Description
IDeclaration targetDeclaration

The declaration to which the attribute must be added.

INamedType attributeType

The type of the attribute.

String title

An optional title of the CodeFix, displayed to the user in the light bulb or refactoring menu. When not specified, the title is generated from the other parameters.

Returns
Type Description
CodeFix

AddAttribute(IDeclaration, Func<AttributeConstruction>, String)

Creates a CodeFix that adds a custom attribute to a declaration, with constructor or named arguments, by providing an AttributeConstruction.

Declaration
public static CodeFix AddAttribute(IDeclaration targetDeclaration, Func<AttributeConstruction> constructAttribute, string title)
Parameters
Type Name Description
IDeclaration targetDeclaration

The declaration to which the attribute must be added.

Func<AttributeConstruction> constructAttribute

A delegate that returns the AttributeConstruction from which the new attribute should be created. This delegate is executed only if the code fix is executed.

String title

The title of the CodeFix, displayed to the user in the light bulb or refactoring menu.

Returns
Type Description
CodeFix