CodeAttributeDeclaration CodeAttributeDeclaration CodeAttributeDeclaration CodeAttributeDeclaration Class

定義

表示屬性宣告。Represents an attribute declaration.

public ref class CodeAttributeDeclaration
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeAttributeDeclaration
type CodeAttributeDeclaration = class
Public Class CodeAttributeDeclaration
繼承
CodeAttributeDeclarationCodeAttributeDeclarationCodeAttributeDeclarationCodeAttributeDeclaration
屬性

範例

下列程式碼範例CodeAttributeDeclaration會建立, CLSCompliantAttribute其宣告的引數false為:The following code example creates a CodeAttributeDeclaration that declares a CLSCompliantAttribute with an argument of false:

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::CodeDom;
using namespace System::CodeDom::Compiler;

int main()
{
    // Declare a new type called Class1.
    CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration("Class1");

    // Declare a new code attribute
    CodeAttributeDeclaration^ codeAttrDecl = gcnew CodeAttributeDeclaration(
        "System.CLSCompliantAttribute",
        gcnew CodeAttributeArgument(gcnew 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, gcnew CodeGeneratorOptions());
}

// The CPP code generator produces the following source code for the preceeding example code:
//
//[System.CLSCompliantAttribute(false)]
//public class Class1 {
//}
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 {
// }
Imports System.CodeDom
Imports System.CodeDom.Compiler

Public Class CodeGenExample

    Shared Sub Main
        ' Declare a new type called Class1.
        Dim class1 as New CodeTypeDeclaration("Class1")

        '  Declare a new code attribute
        Dim codeAttrDecl As New CodeAttributeDeclaration(
            "System.CLSCompliantAttribute",
            new CodeAttributeArgument(new CodePrimitiveExpression(false)))
        class1.CustomAttributes.Add(codeAttrDecl)

        ' Create a Visual Basic code provider
        Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")

        ' Generate code and send the output to the console
        provider.GenerateCodeFromType(class1, Console.Out, New CodeGeneratorOptions())
    End Sub

End Class

' The Visual Basic code generator produces the following source code for the preceeding example code:
'
' <System.CLSCompliantAttribute(false)>  _
' Public Class Class1
' End Class

備註

CodeAttributeDeclaration可以用來表示宣告屬性的運算式。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. CodeAttributeArgument可以用來表示屬性的每個引數。A CodeAttributeArgument can be used to represent each argument for the attribute.

建構函式

CodeAttributeDeclaration() CodeAttributeDeclaration() CodeAttributeDeclaration() CodeAttributeDeclaration()

初始化 CodeAttributeDeclaration 類別的新執行個體。Initializes a new instance of the CodeAttributeDeclaration class.

CodeAttributeDeclaration(CodeTypeReference) CodeAttributeDeclaration(CodeTypeReference) CodeAttributeDeclaration(CodeTypeReference) CodeAttributeDeclaration(CodeTypeReference)

使用指定的程式碼型別參考,初始化 CodeAttributeDeclaration 類別的新執行個體。Initializes a new instance of the CodeAttributeDeclaration class using the specified code type reference.

CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[]) CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[]) CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[]) CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[])

使用指定的程式碼型別參考和引數,初始化 CodeAttributeDeclaration 類別的新執行個體。Initializes a new instance of the CodeAttributeDeclaration class using the specified code type reference and arguments.

CodeAttributeDeclaration(String) CodeAttributeDeclaration(String) CodeAttributeDeclaration(String) CodeAttributeDeclaration(String)

使用指定的名稱來初始化 CodeAttributeDeclaration 類別的新執行個體。Initializes a new instance of the CodeAttributeDeclaration class using the specified name.

CodeAttributeDeclaration(String, CodeAttributeArgument[]) CodeAttributeDeclaration(String, CodeAttributeArgument[]) CodeAttributeDeclaration(String, CodeAttributeArgument[]) CodeAttributeDeclaration(String, CodeAttributeArgument[])

使用指定的名稱和引數,初始化 CodeAttributeDeclaration 類別的新執行個體。Initializes a new instance of the CodeAttributeDeclaration class using the specified name and arguments.

屬性

Arguments Arguments Arguments Arguments

取得屬性的引數。Gets the arguments for the attribute.

AttributeType AttributeType AttributeType AttributeType

取得程式碼屬性宣告的程式碼型別參考。Gets the code type reference for the code attribute declaration.

Name Name Name Name

取得或設定正在宣告的屬性名稱。Gets or sets the name of the attribute being declared.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱