AttributeCollection.Item[] プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定したインデックスを持つ属性を取得します。
オーバーロード
| 名前 | 説明 |
|---|---|
| Item[Int32] |
指定したインデックス番号を持つ属性を取得します。 |
| Item[Type] |
指定した型の属性を取得します。 |
Item[Int32]
指定したインデックス番号を持つ属性を取得します。
public:
virtual property Attribute ^ default[int] { Attribute ^ get(int index); };
public virtual Attribute this[int index] { get; }
member this.Item(int) : Attribute
Default Public Overridable ReadOnly Property Item(index As Integer) As Attribute
パラメーター
- index
- Int32
AttributeCollectionの 0 から始まるインデックス。
プロパティ値
指定したインデックス番号を持つ Attribute 。
例
次のコード例では、 Item[] プロパティを使用して、インデックス番号で指定された Attribute の名前をテキスト ボックスに出力します。 インデックス番号は 0 から始まるため、次のコード例では、テキスト ボックスに 2 番目の Attribute の名前を出力します。 フォームに button1 と textBox1 が作成されていることを前提としています。
private:
void PrintIndexItem()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection^ attributes;
attributes = TypeDescriptor::GetAttributes( button1 );
// Prints the second attribute's name.
textBox1->Text = attributes[ 1 ]->ToString();
}
private void PrintIndexItem() {
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection attributes;
attributes = TypeDescriptor.GetAttributes(button1);
// Prints the second attribute's name.
textBox1.Text = attributes[1].ToString();
}
Private Sub PrintIndexItem
' Creates a new collection and assigns it the attributes for button1.
Dim attributes As AttributeCollection
attributes = TypeDescriptor.GetAttributes(button1)
' Prints the second attribute's name.
textBox1.Text = attributes(1).ToString
End Sub
注釈
インデックス番号は 0 から始まります。 したがって、そのAttributeにアクセスするには、特定のAttributeの数値位置から 1 を減算する必要があります。 たとえば、3 番目の Attributeを取得するには、 myColl[2]を指定する必要があります。
こちらもご覧ください
適用対象
Item[Type]
指定した型の属性を取得します。
public:
virtual property Attribute ^ default[Type ^] { Attribute ^ get(Type ^ attributeType); };
public virtual Attribute? this[Type attributeType] { get; }
public virtual Attribute this[Type attributeType] { get; }
member this.Item(Type) : Attribute
Default Public Overridable ReadOnly Property Item(attributeType As Type) As Attribute
パラメーター
プロパティ値
指定した型を持つ Attribute 、または属性が存在しない場合は、属性の型の既定値。
例
次のコード例では、コレクションから DesignerAttribute を取得し、その値を出力します。 フォームに button1 と textBox1 が作成されていることを前提としています。
このコード例を実行するには、完全修飾アセンブリ名を指定する必要があります。 完全修飾アセンブリ名を取得する方法については、「アセンブリ 名」を参照してください。
void PrintIndexItem2()
{
// 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;
// You must supply a valid fully qualified assembly name here.
myDesigner = dynamic_cast<DesignerAttribute^>(attributes[ Type::GetType( "Assembly text name, Version, Culture, PublicKeyToken" ) ]);
textBox1->Text = myDesigner->DesignerTypeName;
}
private void PrintIndexItem2() {
// 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;
// You must supply a valid fully qualified assembly name here.
myDesigner = (DesignerAttribute)attributes[Type.GetType("Assembly text name, Version, Culture, PublicKeyToken")];
textBox1.Text = myDesigner.DesignerTypeName;
}
Private Sub PrintIndexItem2
' 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
' You must supply a valid fully qualified assembly name here.
myDesigner = CType(attributes(Type.GetType("Assembly text name, Version, Culture, PublicKeyToken")), DesignerAttribute)
textBox1.Text = myDesigner.DesignerTypeName
End Sub
注釈
属性がコレクションに存在しない場合、このプロパティは属性型の既定値を返します。