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 , объявляющий 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

Комментарии

Можно CodeAttributeDeclaration использовать для представления выражения, объявляющего атрибут. Имя атрибута и аргументы атрибута хранятся в виде свойств объекта. Можно CodeAttributeArgument использовать для представления каждого аргумента атрибута.

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

Имя Описание
CodeAttributeDeclaration()

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

CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[])

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

CodeAttributeDeclaration(CodeTypeReference)

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

CodeAttributeDeclaration(String, CodeAttributeArgument[])

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

CodeAttributeDeclaration(String)

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

Свойства

Имя Описание
Arguments

Возвращает аргументы для атрибута.

AttributeType

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

Name

Возвращает или задает имя объявленного атрибута.

Методы

Имя Описание
Equals(Object)

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

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

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

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

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

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

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

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

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

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

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

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