CodeAttributeDeclaration Класс

Определение

Представляет объявление атрибута.

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
Наследование
CodeAttributeDeclaration
Атрибуты

Примеры

В следующем примере кода создается объект CodeAttributeDeclaration , объявляющий CLSCompliantAttribute аргумент с аргументом 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 представления выражения, объявляющего атрибут. Имя атрибута и аргументы атрибута хранятся в виде свойств объекта. Можно CodeAttributeArgument использовать для представления каждого аргумента для атрибута.

Конструкторы

CodeAttributeDeclaration()

Инициализирует новый экземпляр класса CodeAttributeDeclaration.

CodeAttributeDeclaration(CodeTypeReference)

Инициализирует новый экземпляр класса CodeAttributeDeclaration, используя указанную ссылку типа кода.

CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[])

Инициализирует новый экземпляр класса CodeAttributeDeclaration, используя указанную ссылку типа кода и аргументы.

CodeAttributeDeclaration(String)

Инициализирует новый экземпляр класса CodeAttributeDeclaration с использованием указанного имени.

CodeAttributeDeclaration(String, CodeAttributeArgument[])

Инициализирует новый экземпляр класса CodeAttributeDeclaration, используя указанные имя и аргументы.

Свойства

Arguments

Получает аргументы для атрибута.

AttributeType

Получает ссылку типа кода для объявления атрибута кода.

Name

Получает или задает имя объявляемого атрибута.

Методы

Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Применяется к

См. также раздел