AttributeCollection.Item[] Tulajdonság

Definíció

Lekéri a megadott indexet tartalmazó attribútumot.

Túlterhelések

Name Description
Item[Int32]

Lekéri az attribútumot a megadott indexszámmal.

Item[Type]

Lekéri a megadott típusú attribútumot.

Item[Int32]

Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs

Lekéri az attribútumot a megadott indexszámmal.

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

Paraméterek

index
Int32

A nulla alapú index.AttributeCollection

Tulajdonság értéke

A Attribute megadott indexszámmal.

Példák

Az alábbi példakód a Item[] tulajdonság használatával nyomtatja ki az Attribute indexszám által megadott nevet egy szövegmezőben. Mivel az indexszám nulla alapú, ez a példa a második Attribute nevét nyomtatja ki egy szövegmezőben. Feltételezi button1 , és textBox1 egy űrlapon lett létrehozva.

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

Megjegyzések

Az indexszám nulla alapú. Ezért ki kell vonnia 1-et egy adott Attribute számpozíciójából ahhoz, hogy hozzáférhessen az adotthoz Attribute. A harmadik Attributelekéréséhez például meg kell adnia myColl[2].

Lásd még

A következőre érvényes:

Item[Type]

Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs

Lekéri a megadott típusú attribútumot.

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

Paraméterek

attributeType
Type

Type A Attribute gyűjteményből való lekéréshez.

Tulajdonság értéke

A Attribute megadott típus, vagy ha az attribútum nem létezik, az attribútumtípus alapértelmezett értéke.

Példák

Az alábbi példakód lekéri a DesignerAttribute gyűjteményt, és kinyomtatja annak értékét. Ezt feltételezi, button1 és textBox1 egy űrlapon lett létrehozva.

A példakód futtatásához meg kell adnia a teljes szerelvénynevet. A teljes szerelvénynév beszerzéséről további információt a szerelvénynevek című témakörben talál.

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

Megjegyzések

Ha az attribútum nem létezik a gyűjteményben, ez a tulajdonság az attribútumtípus alapértelmezett értékét adja vissza.

Lásd még

A következőre érvényes: