AttributeCollectionとは? わかりやすく解説

AttributeCollection クラス

属性コレクション表します

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Class AttributeCollection
    Implements ICollection, IEnumerable
Dim instance As AttributeCollection
[ComVisibleAttribute(true)] 
public class AttributeCollection : ICollection,
 IEnumerable
[ComVisibleAttribute(true)] 
public ref class AttributeCollection : ICollection,
 IEnumerable
/** @attribute ComVisibleAttribute(true) */ 
public class AttributeCollection implements
 ICollection, IEnumerable
ComVisibleAttribute(true) 
public class AttributeCollection implements
 ICollection, IEnumerable
解説解説

AttributeCollection クラス読み取り専用であり、属性追加または削除を行うためのメソッド実装していません。これらのメソッド実装するには、このクラスから継承する必要があります

コレクション内に存在する属性の数を調べるには、Count プロパティ使用します

また、このクラスメソッド使用してコレクションに対してその内容照会することもできます指定した属性または属性配列コレクション内に存在するかどうか確認するには、Contains メソッド呼び出します。指定した属性または属性配列コレクション内に存在し、その属性の値がコレクション内の値と同じかどうか確認するには、Matches メソッド呼び出します。

ほとんどの属性には既定値ありますが、必須ではありません。属性既定値ない場合、型を取るインデックス付きプロパティnull 参照 (Visual Basic では Nothing) を返します。独自の属性定義する場合は、引数とらないコンストラクタ提供するか、"Default" という名前の属性型パブリック静的フィールド定義することによって、既定値宣言できます

メモメモ

このクラス適用される HostProtectionAttribute 属性Resources プロパティの値は、Synchronization です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的にはアイコンダブルクリックコマンド入力、またはブラウザURL入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラストピックまたは「SQL Server プログラミングホスト保護属性」を参照してください

使用例使用例

最初コード例では、コレクション内に BrowsableAttribute が設定されているかどうか確認します2 番目のコード例では、ボタンの DescriptionAttribute の実際の値を取得します。どちらの例でも、フォーム上に button1textBox1作成されていることを前提としています。属性使用するのは、属性設定されているかどうか確認するか、属性の値にアクセスする場合です。

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.Object
  System.ComponentModel.AttributeCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AttributeCollection メンバ
System.ComponentModel 名前空間
Attribute
BrowsableAttribute
DescriptionAttribute

AttributeCollection クラス

ASP.NET サーバー コントロール要素開始タグ宣言されすべての属性へのオブジェクト モデル アクセス提供します。このクラス継承できません。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 AttributeCollection
Dim instance As AttributeCollection
public sealed class AttributeCollection
public ref class AttributeCollection sealed
public final class AttributeCollection
public final class AttributeCollection
解説解説
使用例使用例

次に示すコードは、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
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
  System.Web.UI.AttributeCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

AttributeCollection コンストラクタ

AttributeCollection クラス新しインスタンス初期化します。

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

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

パラメータ

attributes

コレクション属性提供する Attribute 型配列

例外例外
例外種類条件

ArgumentNullException

attributesnull 参照 (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";
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

AttributeCollection コンストラクタ

AttributeCollection クラス新しインスタンス初期化します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    bag As StateBag _
)
Dim bag As StateBag

Dim instance As New AttributeCollection(bag)
public AttributeCollection (
    StateBag bag
)
public:
AttributeCollection (
    StateBag^ bag
)
public AttributeCollection (
    StateBag bag
)
public function AttributeCollection (
    bag : StateBag
)

パラメータ

bag

サーバー コントロール開始タグ属性キーとその値を格納している StateBag オブジェクト

使用例使用例

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

myAttributeCollection = New AttributeCollection(ViewState)
myAttributeCollection = new AttributeCollection(ViewState);
myAttributeCollection = 
    new System.Web.UI.AttributeCollection(get_ViewState());
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AttributeCollection クラス
AttributeCollection メンバ
System.Web.UI 名前空間
StateBag

AttributeCollection フィールド


AttributeCollection プロパティ


AttributeCollection プロパティ


AttributeCollection メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator IDictionary の IEnumerator を返します
参照参照

関連項目

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

AttributeCollection クラス
System.Web.UI 名前空間
Attributes
Attributes

AttributeCollection メンバ

属性コレクション表します

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド AttributeCollection AttributeCollection クラス新しインスタンス初期化します。
パブリック フィールドパブリック フィールド
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator IDictionary の IEnumerator を返します
インターフェイスの明示的な実装 System.Collections.ICollection.SyncRoot コレクションへのアクセス同期するために使用できるオブジェクト取得します
参照参照

関連項目

AttributeCollection クラス
System.ComponentModel 名前空間
Attribute
BrowsableAttribute
DescriptionAttribute

AttributeCollection メンバ

ASP.NET サーバー コントロール要素開始タグ宣言されすべての属性へのオブジェクト モデル アクセス提供します。このクラス継承できません。

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド AttributeCollection 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 から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

AttributeCollection クラス
System.Web.UI 名前空間
Attributes
Attributes



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「AttributeCollection」の関連用語

AttributeCollectionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AttributeCollectionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS