CodeAttributeArgument クラス
アセンブリ: System (system.dll 内)
構文
<SerializableAttribute> _ <ComVisibleAttribute(True)> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ Public Class CodeAttributeArgument
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] public class CodeAttributeArgument
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] public ref class CodeAttributeArgument
CodeAttributeArgument を使用して、属性コンストラクタの単一の引数の値か、または属性のプロパティを初期化する値を表すことができます。
Value プロパティは、引数の値を示します。Name プロパティは (使用されている場合)、値を代入する属性のプロパティの名前を示します。
属性宣言は、多くの場合、実行時に属性のコンストラクタに渡されるいくつかの引数によって初期化されます。属性のコンストラクタに引数を渡すには、それぞれの引数に対応する CodeAttributeArgument を CodeAttributeDeclaration の Arguments コレクションに追加します。初期化する必要があるのは、各 CodeAttributeArgument の Value プロパティだけです。コレクション内の引数の順序は、属性のコンストラクタのメソッド シグネチャにある引数の順序に対応している必要があります。
設定するプロパティの名前を示す CodeAttributeArgument をそのプロパティに設定する値と共に提供することで、コンストラクタを通じて利用できない属性のプロパティを設定することもできます。
クラスを作成し、コード属性を追加して、クラスがシリアル化でき、今後使用しないことを宣言するコードを次に示します。
// Declare a new type called Class1. CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1"); // Use attributes to mark the class as serializable and obsolete. CodeAttributeDeclaration codeAttrDecl = new CodeAttributeDeclaration( "System.Serializable"); class1.CustomAttributes.Add(codeAttrDecl); CodeAttributeArgument codeAttr = new CodeAttributeArgument( new CodePrimitiveExpression("This class is obsolete.")); codeAttrDecl = new CodeAttributeDeclaration("System.Obsolete", codeAttr); class1.CustomAttributes.Add(codeAttrDecl); // A C# code generator produces the following source code for the preceeding example code: // [System.Serializable()] // [System.Obsolete("This class is obsolete.")] // public class Class1 { // }
' Declare a new type called Class1. Dim class1 As New CodeTypeDeclaration("Class1") ' Use attributes to mark the class as serializable and obsolete. Dim codeAttrDecl As New CodeAttributeDeclaration("System.Serializable") class1.CustomAttributes.Add(codeAttrDecl) Dim codeAttr As New CodeAttributeArgument( _ new CodePrimitiveExpression("This class is obsolete.")) codeAttrDecl = New CodeAttributeDeclaration("System.Obsolete", codeAttr) class1.CustomAttributes.Add(codeAttrDecl) ' A Visual Basic code generator produces the following source code for the preceeding example code: ' <System.Serializable(), _ ' System.Obsolete("This class is obsolete.")> _ ' Public Class Class1 ' End Class
System.CodeDom.CodeAttributeArgument
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
CodeAttributeArgument メンバ
System.CodeDom 名前空間
CodeAttributeDeclaration
CodeAttributeArgumentCollection
- CodeAttributeArgument クラスのページへのリンク