次の方法で共有


AttributeCollection.Item プロパティ (Type)

指定した型の属性を取得します。

[C#] C# では、このプロパティは AttributeCollection クラスのインデクサになります。

Overloads Public Overridable Default ReadOnly Property Item( _
   ByVal attributeType As Type _) As Attribute
[C#]
public virtual Attribute this[TypeattributeType] {get;}
[C++]
public: __property virtual Attribute* get_Item(Type* attributeType);
[JScript]
returnValue = AttributeCollectionObject.Item(attributeType);またはreturnValue = AttributeCollectionObject(attributeType);

[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。

引数 [JScript]

  • attributeType
    コレクションから取得する AttributeType

パラメータ [Visual Basic, C#, C++]

  • attributeType
    コレクションから取得する AttributeType

プロパティ値

指定した型の Attribute 。そのような属性が存在しない場合は、指定した属性型の既定値。

解説

コレクション内にそのような属性が存在しない場合、このプロパティは指定した属性型の既定値を返します。

使用例

コレクションから DesignerAttribute を取得し、その値を出力する例を次に示します。この例は、フォーム上に button1textBox1 が作成されていることを前提としています。

このコード例を実行するには、アセンブリの完全限定名を指定する必要があります。アセンブリの完全限定名を取得する方法については、「 アセンブリ名 」を参照してください。

 
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

[C#] 
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;
 }


[C++] 
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 = dynamic_cast<DesignerAttribute*>
            (attributes->Item[Type::GetType("Assembly text name, Version, Culture, PublicKeyToken")]);
        textBox1->Text = myDesigner->DesignerTypeName;
    }


[JScript] 
private function PrintIndexItem2() {
    // 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.
    try{
        var myDesigner : DesignerAttribute; 
        myDesigner = DesignerAttribute(attributes[System.ComponentModel.DesignerAttribute]);
        textBox1.Text = myDesigner.DesignerTypeName;
        Console.WriteLine(textBox1.Text);
    }
    catch(e )
    {
        Console.Write(e);
    }
 }

必要条件

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

参照

AttributeCollection クラス | AttributeCollection メンバ | System.ComponentModel 名前空間 | AttributeCollection.Item オーバーロードの一覧 | Attribute