AttributeUsageAttribute クラス

別の属性クラスの使用方法を指定します。このクラスは継承できません。

この型のすべてのメンバの一覧については、AttributeUsageAttribute メンバ を参照してください。

System.Object
   System.Attribute
      System.AttributeUsageAttribute

<AttributeUsage(AttributeTargets.Class)>
<Serializable>
NotInheritable Public Class AttributeUsageAttribute   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Class)]
[Serializable]
public sealed class AttributeUsageAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Class)]
[Serializable]
public __gc __sealed class AttributeUsageAttribute : public   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Class)
 Serializable
class AttributeUsageAttribute extends Attribute

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

独自の属性クラスを定義している場合、その属性クラスに AttributeUsageAttribute を配置することによって、そのクラスの使用方法を制御できます。制御対象とする属性クラスは、 Attribute から直接または間接に派生したものである必要があります。

属性クラスには、位置指定パラメータと名前付きパラメータがあります。属性クラスの各パブリック コンストラクタは、そのクラスの位置指定パラメータについて、有効なシーケンスを定義します。名前付きパラメータは、属性クラスの非静的で、パブリックで、読み取り/書き込み可能なフィールドまたはプロパティで定義されます。

AttributeUsageAttribute の 3 つのプロパティは、次のパラメータを定義することによって設定します。

この位置指定パラメータは、制御対象とする属性を配置できるプログラム要素を指定します。属性を配置できるすべての要素は、 AttributeTargets 列挙子でリストされます。ビット単位の OR 演算を使用して複数の AttributeTargets 値を組み合わせて、有効なプログラム要素を適宜組み合わせて取得できます。

この名前付きパラメータは、制御対象とする属性を特定のプログラム要素に対して複数回指定できるかどうかを指定します。

この名前付きパラメータは、派生クラスおよびオーバーライドするメンバが、制御対象とする属性を継承できるかどうかを指定します。

属性の使用方法については、 Attribute のトピックおよび「 属性を使用したメタデータの拡張 」を参照してください。

必要条件

名前空間: System

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

AttributeUsageAttribute メンバ | System 名前空間 | Attribute | AttributeTargets | 属性を使用したメタデータの拡張