AttributeCollection.Item[] Właściwość

Definicja

Pobiera atrybut z określonym indeksem.

Przeciążenia

Item[Int32]

Pobiera atrybut z określonym numerem indeksu.

Item[Type]

Pobiera atrybut o określonym typie.

Item[Int32]

Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs

Pobiera atrybut z określonym numerem indeksu.

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

Indeks oparty na zerowej wartości AttributeCollection.

Wartość właściwości

Element Attribute z określonym numerem indeksu.

Przykłady

Poniższy przykład kodu używa Item[] właściwości do drukowania nazwy Attribute określonej przez numer indeksu w polu tekstowym. Ponieważ numer indeksu jest oparty na zera, ten przykład kodu drukuje nazwę sekundy Attribute w polu tekstowym. button1 Zakłada i textBox1 zostały utworzone w formularzu.

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

Uwagi

Liczba indeksów jest oparta na zerowej liczbie. W związku z tym należy odjąć wartość 1 od pozycji liczbowej określonej Attribute w celu uzyskania dostępu do tego Attributeelementu . Aby na przykład uzyskać trzeci Attributeelement , należy określić myColl[2]wartość .

Zobacz też

Dotyczy

Item[Type]

Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs

Pobiera atrybut o określonym typie.

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

Element Type do Attribute pobrania z kolekcji.

Wartość właściwości

Element Attribute o określonym typie lub, jeśli atrybut nie istnieje, wartość domyślna dla typu atrybutu.

Przykłady

Poniższy przykład kodu pobiera element DesignerAttribute z kolekcji i drukuje jego wartość. Przyjęto założenie, że button1 i textBox1 zostały utworzone w formularzu.

Aby ten przykładowy kod zadziałał, należy podać w pełni kwalifikowaną nazwę zestawu. Aby uzyskać informacje o sposobie uzyskania w pełni kwalifikowanej nazwy zestawu, zobacz Nazwy zestawów.

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

Uwagi

Jeśli atrybut nie istnieje w kolekcji, ta właściwość zwraca wartość domyślną dla typu atrybutu.

Zobacz też

Dotyczy