AttributeCollection.Item[] Vlastnost

Definice

Získá atribut se zadaným indexem.

Přetížení

Name Description
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
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 .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, tento příklad kódu vytiskne název sekundy Attribute v textovém poli. Předpokládá button1 a textBox1 byl vytvořen 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 je nutné odečíst hodnotu 1 od číselné pozice konkrétního Attribute , abyste k němu Attributeměli přístup . Chcete-li například získat třetí Attribute, je třeba zadat myColl[2].

Viz také

Platí pro

Item[Type]

Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
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

Z TypeAttribute kolekce se dostanete.

Hodnota vlastnosti

S Attribute zadaným typem nebo, pokud atribut neexistuje, výchozí hodnota 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í tohoto příkladu kódu musíte zadat plně kvalifikovaný název sestavení. Informace o získání plně kvalifikovaného názvu 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