CodeAttributeDeclaration Třída

Definice

Představuje deklaraci atributu.

public ref class CodeAttributeDeclaration
public class CodeAttributeDeclaration
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttributeDeclaration
type CodeAttributeDeclaration = class
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeAttributeDeclaration = class
Public Class CodeAttributeDeclaration
Dědičnost
CodeAttributeDeclaration
Atributy

Příklady

Následující příklad kódu vytvoří, CodeAttributeDeclaration který deklaruje s argumentem CLSCompliantAttributefalse:

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

Poznámky

Lze CodeAttributeDeclaration použít k reprezentaci výrazu, který deklaruje atribut. Název atributu a argumenty atributu jsou uloženy jako vlastnosti objektu. A CodeAttributeArgument lze použít k reprezentaci každého argumentu pro atribut.

Konstruktory

Name Description
CodeAttributeDeclaration()

Inicializuje novou instanci CodeAttributeDeclaration třídy.

CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[])

Inicializuje novou instanci CodeAttributeDeclaration třídy pomocí zadaného odkazu na typ kódu a argumenty.

CodeAttributeDeclaration(CodeTypeReference)

Inicializuje novou instanci CodeAttributeDeclaration třídy pomocí zadaného odkazu na typ kódu.

CodeAttributeDeclaration(String, CodeAttributeArgument[])

Inicializuje novou instanci CodeAttributeDeclaration třídy pomocí zadaného názvu a argumentů.

CodeAttributeDeclaration(String)

Inicializuje novou instanci CodeAttributeDeclaration třídy pomocí zadaného názvu.

Vlastnosti

Name Description
Arguments

Získá argumenty pro atribut.

AttributeType

Získá odkaz na typ kódu pro deklaraci atributu kódu.

Name

Získá nebo nastaví název deklarovaného atributu.

Metody

Name Description
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Viz také