AttributeCollection.Item[] Egenskap

Definition

Hämtar attributet med det angivna indexet.

Överlagringar

Name Description
Item[Int32]

Hämtar attributet med det angivna indexnumret.

Item[Type]

Hämtar attributet med den angivna typen.

Item[Int32]

Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs

Hämtar attributet med det angivna indexnumret.

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

Parametrar

index
Int32

Det nollbaserade indexet för AttributeCollection.

Egenskapsvärde

Med Attribute det angivna indexnumret.

Exempel

I följande kodexempel används Item[] egenskapen för att skriva ut namnet på det Attribute som anges av indexnumret i en textruta. Eftersom indexnumret är nollbaserat skriver det här kodexemplet ut namnet på det andra Attribute i en textruta. Det förutsätter button1 och textBox1 har skapats i ett formulär.

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

Kommentarer

Indexnumret är nollbaserat. Därför måste du subtrahera 1 från den numeriska positionen för en viss Attribute för att få åtkomst till den Attribute. Om du till exempel vill hämta den tredje Attributemåste du ange myColl[2].

Se även

Gäller för

Item[Type]

Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs
Källa:
AttributeCollection.cs

Hämtar attributet med den angivna typen.

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

Parametrar

attributeType
Type

För TypeAttribute att hämta från samlingen.

Egenskapsvärde

Med Attribute den angivna typen eller, om attributet inte finns, standardvärdet för attributtypen.

Exempel

Följande kodexempel hämtar DesignerAttribute från samlingen och skriver ut dess värde. Det förutsätter att button1 och textBox1 har skapats i ett formulär.

För att det här kodexemplet ska köras måste du ange det fullständigt kvalificerade sammansättningsnamnet. Information om hur du hämtar det fullständigt kvalificerade sammansättningsnamnet finns i Sammansättningsnamn.

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

Kommentarer

Om attributet inte finns i samlingen returnerar den här egenskapen standardvärdet för attributtypen.

Se även

Gäller för