CustomAttribute Class

Represents a custom attribute that can be applied to code declarations.

public class CustomAttribute : CodeObject, ICommentable

Example

var attr = new CustomAttribute(typeof(ObsoleteAttribute));
attr.Arguments.Add(new CustomAttributeArgument(new LiteralExpression("Use NewMethod instead")));

Assert.Equal("""[global::System.ObsoleteAttribute("Use NewMethod instead")]""", attr.ToCsharpString());
Inheritance
CodeObject CustomAttribute
Implements

Constructors

NameDescription
CustomAttribute()
CustomAttribute(TypeReference?)Initializes a new instance of the CustomAttribute class with the specified attribute type.

CustomAttribute overloads

CustomAttribute()

CustomAttribute.cs
public CustomAttribute()

No documentation is available.

CustomAttribute(TypeReference?)

CustomAttribute.cs

Initializes a new instance of the CustomAttribute class with the specified attribute type.

public CustomAttribute(TypeReference? typeReference)
Parameters
typeReference TypeReference?
The type of the attribute.

Properties

NameDescription
Arguments
CommentsAfter
CommentsBefore
Target
Type

No documentation is available.

CommentsAfter

CustomAttribute.cs
public CommentCollection CommentsAfter { get; }

Property value

CommentCollection

No documentation is available.

CommentsBefore

CustomAttribute.cs
public CommentCollection CommentsBefore { get; }

Property value

CommentCollection

No documentation is available.

public CustomAttributeTarget? Target { get; }

No documentation is available.

public TypeReference? Type { get; set; }

Property value

TypeReference?

No documentation is available.