CodeAttributeDeclaration 类

定义

表示特性声明。

C#
public class CodeAttributeDeclaration
C#
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttributeDeclaration
继承
CodeAttributeDeclaration
属性

示例

下面的代码示例创建一个 CodeAttributeDeclaration ,用于声明 CLSCompliantAttribute 具有 参数的 false

C#
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 {
// }

注解

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)

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅