AttributeCollection.Item[] Proprietà

Definizione

Ottiene l'attributo con l'indice specificato.

Overload

Item[Int32]

Ottiene l'attributo con il numero di indice specificato.

Item[Type]

Ottiene l'attributo con il tipo specificato.

Item[Int32]

Source:
AttributeCollection.cs
Source:
AttributeCollection.cs
Source:
AttributeCollection.cs

Ottiene l'attributo con il numero di indice specificato.

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

Parametri

index
Int32

Indice in base zero di AttributeCollection.

Valore della proprietà

Oggetto Attribute con il numero di indice specificato.

Esempio

Nell'esempio di codice seguente viene utilizzata la Item[] proprietà per stampare il nome dell'oggetto Attribute specificato dal numero di indice in una casella di testo. Poiché il numero di indice è in base zero, in questo esempio di codice viene stampato il nome del secondo Attribute in una casella di testo. Si presuppone button1 che e textBox1 siano stati creati in un modulo.

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

Commenti

Il numero di indice è in base zero. Pertanto, è necessario sottrarre 1 dalla posizione numerica di un particolare Attribute per accedere a tale Attributeoggetto . Ad esempio, per ottenere il terzo Attribute, è necessario specificare myColl[2].

Vedi anche

Si applica a

Item[Type]

Source:
AttributeCollection.cs
Source:
AttributeCollection.cs
Source:
AttributeCollection.cs

Ottiene l'attributo con il tipo specificato.

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

Parametri

attributeType
Type

Oggetto Type di Attribute da ottenere dall'insieme.

Valore della proprietà

Oggetto Attribute con il tipo specificato o, se l'attributo non esiste, il valore predefinito per il tipo di attributo.

Esempio

Nell'esempio di codice seguente viene ottenuto DesignerAttribute dall'insieme e ne viene stampato il valore. Si presuppone che button1 e textBox1 siano stati creati in un modulo.

Per eseguire questo esempio di codice, è necessario specificare il nome completo dell'assembly. Per informazioni su come ottenere il nome completo dell'assembly, vedere Nomi assembly.

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

Commenti

Se l'attributo non esiste nell'insieme, questa proprietà restituisce il valore predefinito per il tipo di attributo.

Vedi anche

Si applica a