CodeAttributeDeclaration Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Represents an attribute declaration.

Namespace:   System.CodeDom
Assembly:  System (in System.dll)

System.Object
  System.CodeDom.CodeAttributeDeclaration

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeAttributeDeclaration

NameDescription
System_CAPS_pubmethodCodeAttributeDeclaration()

Initializes a new instance of the CodeAttributeDeclaration class.

System_CAPS_pubmethodCodeAttributeDeclaration(CodeTypeReference)

Initializes a new instance of the CodeAttributeDeclaration class using the specified code type reference.

System_CAPS_pubmethodCodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[])

Initializes a new instance of the CodeAttributeDeclaration class using the specified code type reference and arguments.

System_CAPS_pubmethodCodeAttributeDeclaration(String)

Initializes a new instance of the CodeAttributeDeclaration class using the specified name.

System_CAPS_pubmethodCodeAttributeDeclaration(String, CodeAttributeArgument[])

Initializes a new instance of the CodeAttributeDeclaration class using the specified name and arguments.

NameDescription
System_CAPS_pubpropertyArguments

Gets the arguments for the attribute.

System_CAPS_pubpropertyAttributeType

Gets the code type reference for the code attribute declaration.

System_CAPS_pubpropertyName

Gets or sets the name of the attribute being declared.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

A CodeAttributeDeclaration can be used to represent an expression that declares an attribute. The attribute name and the arguments for the attribute are stored as properties of the object. A CodeAttributeArgument can be used to represent each argument for the attribute.

The following code example creates a CodeAttributeDeclaration that declares a CLSCompliantAttribute with an argument of false:

using System;
using System.CodeDom;
using System.CodeDom.Compiler;

public class CodeGenExample
{
    static void Main()
    {
        // Declare a new type called Class1.
        CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");

        // Declare a new code attribute
        CodeAttributeDeclaration codeAttrDecl = new CodeAttributeDeclaration(
            "System.CLSCompliantAttribute",
            new CodeAttributeArgument(new CodePrimitiveExpression(false)));
        class1.CustomAttributes.Add(codeAttrDecl);

        // Create a C# code provider
        CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

        // Generate code and send the output to the console
        provider.GenerateCodeFromType(class1, Console.Out, new CodeGeneratorOptions());
    }
}

// The C# code generator produces the following source code for the preceeding example code:
//
// [System.CLSCompliantAttribute(false)]
// public class Class1 {
// }

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: