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 声明 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 可用于表示声明属性的表达式。 属性的属性名称和参数存储为对象的属性。 A 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)

适用于

另请参阅