CodeAttributeDeclaration 類別

定義

代表屬性宣告。

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

範例

以下程式碼範例建立 , CodeAttributeDeclaration 宣告 a CLSCompliantAttribute 的參數 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 {
// }
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

備註

A CodeAttributeDeclaration 可用來表示一個宣告屬性的表達式。 屬性名稱與屬性的參數會儲存為物件的屬性。 CodeAttributeArgument A 可用來表示屬性的每個參數。

建構函式

名稱 Description
CodeAttributeDeclaration()

初始化 CodeAttributeDeclaration 類別的新執行個體。

CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[])

使用指定的程式碼類型參考與參數初始化該 CodeAttributeDeclaration 類別的新實例。

CodeAttributeDeclaration(CodeTypeReference)

使用指定的程式碼型別參考初始化該 CodeAttributeDeclaration 類別的新實例。

CodeAttributeDeclaration(String, CodeAttributeArgument[])

使用指定的名稱和參數初始化該類別的新實例 CodeAttributeDeclaration

CodeAttributeDeclaration(String)

使用指定名稱初始化該類別的新實例 CodeAttributeDeclaration

屬性

名稱 Description
Arguments

取得屬性的論點。

AttributeType

取得程式碼屬性宣告的程式碼型別參考。

Name

取得或設定被宣告屬性的名稱。

方法

名稱 Description
Equals(Object)

判斷指定的 物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於

另請參閱