Open sandboxFocus

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