AttributeCollection クラス
アセンブリ: System (system.dll 内)


AttributeCollection クラスは読み取り専用であり、属性の追加または削除を行うためのメソッドは実装していません。これらのメソッドを実装するには、このクラスから継承する必要があります。
コレクション内に存在する属性の数を調べるには、Count プロパティを使用します。
また、このクラスのメソッドを使用して、コレクションに対してその内容を照会することもできます。指定した属性または属性配列がコレクション内に存在するかどうかを確認するには、Contains メソッドを呼び出します。指定した属性または属性配列がコレクション内に存在し、その属性の値がコレクション内の値と同じかどうかを確認するには、Matches メソッドを呼び出します。
ほとんどの属性には既定値がありますが、必須ではありません。属性に既定値がない場合、型を取るインデックス付きプロパティは null 参照 (Visual Basic では Nothing) を返します。独自の属性を定義する場合は、引数をとらないコンストラクタを提供するか、"Default" という名前の属性型のパブリック静的フィールドを定義することによって、既定値を宣言できます。
![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、Synchronization です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |

最初のコード例では、コレクション内に BrowsableAttribute が設定されているかどうかを確認します。2 番目のコード例では、ボタンの DescriptionAttribute の実際の値を取得します。どちらの例でも、フォーム上に button1 と textBox1 が作成されていることを前提としています。属性を使用するのは、属性が設定されているかどうかを確認するか、属性の値にアクセスする場合です。
Private Sub ContainsAttribute() ' Creates a new collection and assigns it the attributes for button1. Dim attributes As AttributeCollection attributes = TypeDescriptor.GetAttributes(button1) ' Sets an Attribute to the specific attribute. Dim myAttribute As BrowsableAttribute = BrowsableAttribute.Yes If attributes.Contains(myAttribute) Then textBox1.Text = "button1 has a browsable attribute." Else textBox1.Text = "button1 does not have a browsable attribute." End If End Sub 'ContainsAttribute
private void ContainsAttribute() { // Creates a new collection and assigns it the attributes for button1. AttributeCollection attributes; attributes = TypeDescriptor.GetAttributes(button1); // Sets an Attribute to the specific attribute. BrowsableAttribute myAttribute = BrowsableAttribute.Yes; if (attributes.Contains(myAttribute)) textBox1.Text = "button1 has a browsable attribute."; else textBox1.Text = "button1 does not have a browsable attribute."; }
private: void ContainsAttribute() { // Creates a new collection and assigns it the attributes for button1. AttributeCollection^ attributes; attributes = TypeDescriptor::GetAttributes( button1 ); // Sets an Attribute to the specific attribute. BrowsableAttribute^ myAttribute = BrowsableAttribute::Yes; if ( attributes->Contains( myAttribute ) ) { textBox1->Text = "button1 has a browsable attribute."; } else { textBox1->Text = "button1 does not have a browsable attribute."; } }
private void ContainsAttribute() { // Creates a new collection and assigns it the attributes for button1. AttributeCollection attributes; attributes = TypeDescriptor.GetAttributes(button1); // Sets an Attribute to the specific attribute. BrowsableAttribute myAttribute = BrowsableAttribute.Yes; if (attributes.Contains(myAttribute)) { textBox1.set_Text("button1 has a browsable attribute."); } else { textBox1.set_Text("button1 does not have a browsable attribute."); } } //ContainsAttribute
public function ContainsAttribute() { // Creates a new collection and assigns it the attributes for button1. var attributes : AttributeCollection; attributes = TypeDescriptor.GetAttributes(button1); // Sets an Attribute to the specific attribute. var myAttribute : BrowsableAttribute = BrowsableAttribute.Yes; if (attributes.Contains(myAttribute)) textBox1.Text = "button1 has a browsable attribute."; else textBox1.Text = "button1 does not have a browsable attribute."; }
Private Sub GetAttributeValue() ' Creates a new collection and assigns it the attributes for button1. Dim attributes As AttributeCollection attributes = TypeDescriptor.GetAttributes(button1) ' Gets the designer attribute from the collection. Dim myDesigner As DesignerAttribute myDesigner = CType(attributes(GetType(DesignerAttribute)), DesignerAttribute) ' Prints the value of the attribute in a text box. textBox1.Text = myDesigner.DesignerTypeName End Sub 'GetAttributeValue
private void GetAttributeValue() { // Creates a new collection and assigns it the attributes for button1. AttributeCollection attributes; attributes = TypeDescriptor.GetAttributes(button1); // Gets the designer attribute from the collection. DesignerAttribute myDesigner; myDesigner = (DesignerAttribute)attributes[typeof(DesignerAttribute)]; // Prints the value of the attribute in a text box. textBox1.Text = myDesigner.DesignerTypeName; }
private: void GetAttributeValue() { // Creates a new collection and assigns it the attributes for button1. AttributeCollection^ attributes; attributes = TypeDescriptor::GetAttributes( button1 ); // Gets the designer attribute from the collection. DesignerAttribute^ myDesigner; myDesigner = (DesignerAttribute^)(attributes[DesignerAttribute::typeid]); // Prints the value of the attribute in a text box. textBox1->Text = myDesigner->DesignerTypeName; }
private void GetAttributeValue() { // Creates a new collection and assigns it the attributes for button1. AttributeCollection attributes; attributes = TypeDescriptor.GetAttributes(button1); // Gets the designer attribute from the collection. DesignerAttribute myDesigner; myDesigner = ((DesignerAttribute) (attributes.get_Item(DesignerAttribute.class.ToType()))); // Prints the value of the attribute in a text box. textBox1.set_Text(myDesigner.get_DesignerTypeName()); } //GetAttributeValue
public function GetAttributeValue() { // Creates a new collection and assigns it the attributes for button1. var attributes : AttributeCollection ; attributes = TypeDescriptor.GetAttributes(button1); // Gets the designer attribute from the collection. var myDesigner : DesignerAttribute ; myDesigner = DesignerAttribute(attributes[DesignerAttribute.GetType()]); // Prints the value of the attribute in a text box. if(myDesigner) textBox1.Text = myDesigner.DesignerTypeName; }

System.ComponentModel.AttributeCollection


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AttributeCollection メンバ
System.ComponentModel 名前空間
Attribute
BrowsableAttribute
DescriptionAttribute
AttributeCollection クラス
アセンブリ: System.Web (system.web.dll 内)


属性の大文字小文字の区別は承継元の StateBag クラスが大文字小文字を区別するかどうかに依存します。属性は、値として String オブジェクトを返します。コレクション内に属性がない場合は、null 参照 (Visual Basic では Nothing) を返します。
HTML サーバー コントロールの属性には、すべての HTML サーバー コントロールが継承する Attributes プロパティを通じて、プログラムによりアクセスできます。.NET Framework では、HTML 属性は、その属性が属している HTML サーバー コントロールのプロパティのように扱われます。
すべての Web サーバーが継承する Attributes プロパティを通じて、Web サーバー コントロールに属性を追加することもできます。Web サーバー コントロールについて、このコレクションに格納されている属性は、指定されている Web サーバー コントロールの厳密に型指定されたプロパティには対応していません。

次に示すコードは、myAttributeCollection という名前の新しい AttributeCollection を作成し、その後、ページがポストバック済みかどうかをチェックします。まだポストバックされていない場合は、2 つの属性をコレクションに追加し、コレクション内の属性の数を取得して、各属性のキーをページに書き込みます。ポストバック済みである場合は、変更後の属性数を単に取得し、コレクション内の各属性のキーと値をページに書き込みます。
Dim myAttributeCollection As AttributeCollection = Nothing Sub Page_Load(sender As Object, e As EventArgs) myAttributeCollection = New AttributeCollection(ViewState) Response.Write("<h3> AttributeCollection.AttributeCollection Sample </h3>") If Not IsPostBack Then myAttributeCollection.Add("Color", "Color.Red") myAttributeCollection.Add("BackColor", "Color.blue") Response.Write("Attribute Collection count before PostBack = " & _ myAttributeCollection.Count.ToString()) Response.Write("<br><U><h4>Enumerating Attributes for " & _ "CustomControl before PostBack</h4></U>") Dim keys As IEnumerator = myAttributeCollection.Keys.GetEnumerator() Dim i As Integer = 1 Dim key As String While keys.MoveNext() key = CType(keys.Current, String) Response.Write(i.ToString() + ". " + key + "=" + myAttributeCollection(key) + "<br>") i += 1 End While Else Response.Write("Attribute Collection count after PostBack = " + _ myAttributeCollection.Count.ToString()) Response.Write("<br><U><h4>Enumerating Attributes for " + _ "CustomControl after PostBack</h4></U>") Dim keys As IEnumerator = myAttributeCollection.Keys.GetEnumerator() Dim i As Integer = 1 Dim key As String While keys.MoveNext() key = CType(keys.Current, String) Response.Write(i.ToString() + ". " + key + "=" + myAttributeCollection(key) + "<br>") i += 1 End While End If End Sub
AttributeCollection myAttributeCollection = null; void Page_Load(object sender,EventArgs e) { myAttributeCollection = new AttributeCollection(ViewState); Response.Write("<h3> AttributeCollection.AttributeCollection Sample </h3>"); if (!IsPostBack) { myAttributeCollection.Add("Color" ,"Color.Red"); myAttributeCollection.Add("BackColor","Color.blue"); Response.Write("Attribute Collection count before PostBack = " + myAttributeCollection.Count); Response.Write("<br><U><h4>Enumerating Attributes for CustomControl before PostBack</h4></U>"); IEnumerator keys = myAttributeCollection.Keys.GetEnumerator(); int i =1; String key; while (keys.MoveNext()) { key = (String)keys.Current; Response.Write(i + ". "+key + "=" + myAttributeCollection[key]+"<br>"); i++; } } else { Response.Write("Attribute Collection count after PostBack = "+myAttributeCollection.Count); Response.Write("<br><U><h4>Enumerating Attributes for CustomControl after PostBack</h4></U>"); IEnumerator keys = myAttributeCollection.Keys.GetEnumerator(); int i =1; String key; while (keys.MoveNext()) { key = (String)keys.Current; Response.Write(i + ". "+key + "=" + myAttributeCollection[key]+"<br>"); i++; } } }
System.Web.UI.AttributeCollection myAttributeCollection = null; void Page_Load(Object sender,EventArgs e) { myAttributeCollection = new System.Web.UI.AttributeCollection(get_ViewState()); get_Response(). Write("<h3> AttributeCollection.AttributeCollection Sample </h3>"); if (!get_IsPostBack()) { myAttributeCollection.Add("Color" ,"Color.Red"); myAttributeCollection.Add("BackColor","Color.blue"); get_Response().Write("Attribute Collection count before PostBack = " + myAttributeCollection.get_Count()); get_Response().Write("<br><U><h4>Enumerating Attributes for " + "CustomControl before PostBack</h4></U>"); IEnumerator keys = myAttributeCollection.get_Keys().GetEnumerator(); int i =1; String key; while (keys.MoveNext()) { key = (String)keys.get_Current(); get_Response().Write(i + ". " + key + "=" + myAttributeCollection.get_Item (key) + "<br>"); i++; } } else { get_Response().Write("Attribute Collection count after PostBack = " + myAttributeCollection.get_Count()); get_Response().Write("<br><U><h4>Enumerating Attributes for " + "CustomControl after PostBack</h4></U>"); IEnumerator keys = myAttributeCollection.get_Keys().GetEnumerator(); int i =1; String key; while (keys.MoveNext()) { key = (String)keys.get_Current(); get_Response().Write(i + ". " + key + "=" + myAttributeCollection.get_Item(key)+"<br>"); i++; } } } //Page_Load


System.Web.UI.AttributeCollection


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AttributeCollection コンストラクタ
アセンブリ: System (system.dll 内)

Dim attributes As Attribute() Dim instance As New AttributeCollection(attributes)
public AttributeCollection ( params Attribute[] attributes )
public: AttributeCollection ( ... array<Attribute^>^ attributes )
public AttributeCollection ( Attribute[] attributes )
public function AttributeCollection ( ... attributes : Attribute[] )

例外の種類 | 条件 |
---|---|
ArgumentNullException | attributes が null 参照 (Visual Basic では Nothing) です。 |

button1 の属性を使用して新しい AttributeCollection を作成するコード例を次に示します。この例は、フォーム上に button1 が作成されていることを前提としています。
Dim collection1 As AttributeCollection collection1 = TypeDescriptor.GetAttributes(button1)
AttributeCollection collection1; collection1 = TypeDescriptor.GetAttributes(button1); }
AttributeCollection^ collection1; collection1 = TypeDescriptor::GetAttributes( button1 );
AttributeCollection collection1;
collection1 = TypeDescriptor.GetAttributes(button1);
} //Method
var collection1 : AttributeCollection; collection1 = TypeDescriptor.GetAttributes(button1); textBox1.Text = "The button1 has " + collection1.Count + " attributes"; }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AttributeCollection コンストラクタ
アセンブリ: System.Web (system.web.dll 内)


AttributeCollection コンストラクタを使用して、このクラスのインスタンスを作成し、myAttributeCollection という名前を付け、コントロールの ViewState プロパティをパラメータ引数として渡す例を次に示します。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AttributeCollection フィールド


関連項目
AttributeCollection クラスSystem.ComponentModel 名前空間
Attribute
BrowsableAttribute
DescriptionAttribute
AttributeCollection プロパティ



関連項目
AttributeCollection クラスSystem.ComponentModel 名前空間
Attribute
BrowsableAttribute
DescriptionAttribute
AttributeCollection プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | AttributeCollection オブジェクト内の属性の数を取得します。 |
![]() | CssStyle | 現在の AttributeCollection オブジェクトが属する ASP.NET サーバー コントロールのスタイルのコレクションを取得します。 |
![]() | Item | サーバー コントロールに指定されている属性値を取得または設定します。 |
![]() | Keys | サーバー コントロールの AttributeCollection オブジェクトに格納されているすべての属性に対するキーのコレクションを取得します。 |

AttributeCollection メソッド

名前 | 説明 | |
---|---|---|
![]() | Contains | オーバーロードされます。 指定した属性または属性配列が属性コレクションに格納されているかどうかを判断します。 |
![]() | CopyTo | 指定したインデックスを開始位置として、配列にコレクションをコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | FromExisting | 既存の AttributeCollection から新しい AttributeCollection を作成します。 |
![]() | GetEnumerator | このコレクションの列挙子を取得します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | Matches | オーバーロードされます。 指定した属性または属性配列がコレクション内の属性または属性配列と同じかどうかを判断します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | GetDefaultAttribute | 指定した Type の既定の Attribute を返します。 |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |


関連項目
AttributeCollection クラスSystem.ComponentModel 名前空間
Attribute
BrowsableAttribute
DescriptionAttribute
AttributeCollection メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | サーバー コントロールの AttributeCollection オブジェクトに属性を追加します。 |
![]() | AddAttributes | 属性を HTML として ASP.NET サーバー コントロールに表示する HtmlTextWriter オブジェクトに AttributeCollection クラスの属性を追加します。 |
![]() | Clear | サーバー コントロールの AttributeCollection オブジェクトからすべての属性を削除します。 |
![]() | Equals | オーバーロードされます。 オーバーライドされます。 AttributeCollection コレクションの 2 つのインスタンスが等しいかどうかを示す値を返します。 |
![]() | GetHashCode | オーバーライドされます。 対象のインスタンスのハッシュ コードを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Remove | サーバー コントロールの AttributeCollection オブジェクトから属性を削除します。 |
![]() | Render | 指定した HtmlTextWriter 出力ストリームに属性のコレクションを書き込みます。その後、出力ストリームは、そのコレクションが属する ASP.NET サーバー コントロールにそのコレクションを書き込みます。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

AttributeCollection メンバ
AttributeCollection データ型で公開されるメンバを以下の表に示します。




名前 | 説明 | |
---|---|---|
![]() | Contains | オーバーロードされます。 指定した属性または属性配列が属性コレクションに格納されているかどうかを判断します。 |
![]() | CopyTo | 指定したインデックスを開始位置として、配列にコレクションをコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | FromExisting | 既存の AttributeCollection から新しい AttributeCollection を作成します。 |
![]() | GetEnumerator | このコレクションの列挙子を取得します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | Matches | オーバーロードされます。 指定した属性または属性配列がコレクション内の属性または属性配列と同じかどうかを判断します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | GetDefaultAttribute | 指定した Type の既定の Attribute を返します。 |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.IEnumerable.GetEnumerator | IDictionary の IEnumerator を返します。 |
![]() | System.Collections.ICollection.SyncRoot | コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。 |

関連項目
AttributeCollection クラスSystem.ComponentModel 名前空間
Attribute
BrowsableAttribute
DescriptionAttribute
AttributeCollection メンバ
ASP.NET サーバー コントロール要素の開始タグで宣言されたすべての属性へのオブジェクト モデル アクセスを提供します。このクラスは継承できません。
AttributeCollection データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Count | AttributeCollection オブジェクト内の属性の数を取得します。 |
![]() | CssStyle | 現在の AttributeCollection オブジェクトが属する ASP.NET サーバー コントロールのスタイルのコレクションを取得します。 |
![]() | Item | サーバー コントロールに指定されている属性値を取得または設定します。 |
![]() | Keys | サーバー コントロールの AttributeCollection オブジェクトに格納されているすべての属性に対するキーのコレクションを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Add | サーバー コントロールの AttributeCollection オブジェクトに属性を追加します。 |
![]() | AddAttributes | 属性を HTML として ASP.NET サーバー コントロールに表示する HtmlTextWriter オブジェクトに AttributeCollection クラスの属性を追加します。 |
![]() | Clear | サーバー コントロールの AttributeCollection オブジェクトからすべての属性を削除します。 |
![]() | Equals | オーバーロードされます。 オーバーライドされます。 AttributeCollection コレクションの 2 つのインスタンスが等しいかどうかを示す値を返します。 |
![]() | GetHashCode | オーバーライドされます。 対象のインスタンスのハッシュ コードを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Remove | サーバー コントロールの AttributeCollection オブジェクトから属性を削除します。 |
![]() | Render | 指定した HtmlTextWriter 出力ストリームに属性のコレクションを書き込みます。その後、出力ストリームは、そのコレクションが属する ASP.NET サーバー コントロールにそのコレクションを書き込みます。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- AttributeCollectionのページへのリンク