Share via


AttributeCollection.Item[] Vlastnost

Definice

Získá atribut se zadaným indexem.

Přetížení

Item[Int32]

Získá atribut se zadaným číslem indexu.

Item[Type]

Získá atribut se zadaným typem.

Item[Int32]

Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs

Získá atribut se zadaným číslem indexu.

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

Parametry

index
Int32

Index založený na nule pro AttributeCollection.

Hodnota vlastnosti

Hodnota Attribute se zadaným číslem indexu.

Příklady

Následující příklad kódu používá Item[] vlastnost k vytištění názvu zadaného Attribute číslem indexu v textovém poli. Vzhledem k tomu, že číslo indexu je založené na nule, vytiskne tento příklad kódu název sekundy Attribute v textovém poli. Předpokládá button1 a textBox1 že byly vytvořeny ve formuláři.

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

Poznámky

Číslo indexu je založené na nule. Proto musíte odečíst hodnotu 1 od číselné pozice konkrétního určitého Attribute , abyste měli přístup k této hodnotě Attribute. Pokud chcete například získat třetí Attributehodnotu , musíte zadat myColl[2].

Viz také

Platí pro

Item[Type]

Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs

Získá atribut se zadaným typem.

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

Parametry

attributeType
Type

The Type of the Attribute get from the collection.

Hodnota vlastnosti

Hodnota Attribute se zadaným typem nebo, pokud atribut neexistuje, výchozí hodnotou pro typ atributu.

Příklady

Následující příklad kódu získá DesignerAttribute z kolekce a vytiskne jeho hodnotu. Předpokládá, že button1 a textBox1 byly vytvořeny ve formuláři.

Pro spuštění této ukázky kódu je nutné zadat plně kvalifikovaný název. Informace o tom, jak získat plně kvalifikovaný název sestavení, naleznete v tématu Názvy sestavení.

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

Poznámky

Pokud atribut v kolekci neexistuje, vrátí tato vlastnost výchozí hodnotu pro typ atributu.

Viz také

Platí pro