MetalamaAPI documentationAspect APIMetalama.​Framework.​Code­FixesCode­Fix­FactoryAdd­Attribute
Open sandboxFocus

CodeFixFactory.AddAttribute Method

AddAttribute(IDeclaration, Type, String)

Creates a CodeFix that adds a custom attribute to a declaration, without constructor or named arguments, by specifying the reflection System.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.

System.Type attributeType

The type of the attribute.

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

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

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

System.String title

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

Returns
Type Description
CodeFix