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 の引数falseを使用して をCLSCompliantAttribute宣言する を作成します。

#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)

適用対象

こちらもご覧ください