AttributeCollection.Item[] Propiedad

Definición

Obtiene el atributo que tiene el índice especificado.

Sobrecargas

Item[Int32]

Obtiene el atributo que tiene el número de índice especificado.

Item[Type]

Obtiene el atributo que tiene el tipo especificado.

Item[Int32]

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

Obtiene el atributo que tiene el número de índice especificado.

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

Parámetros

index
Int32

Índice basado en cero de AttributeCollection.

Valor de propiedad

Attribute que tiene el número de índice especificado.

Ejemplos

En el ejemplo de código siguiente se usa la Item[] propiedad para imprimir el nombre del especificado por el número de Attribute índice en un cuadro de texto. Dado que el número de índice está basado en cero, este ejemplo de código imprime el nombre del segundo Attribute en un cuadro de texto. Se supone button1 que y textBox1 se han creado en un formulario.

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

Comentarios

El número de índice está basado en cero. Por lo tanto, debe restar 1 de la posición numérica de un determinado Attribute para tener acceso a ese Attribute. Por ejemplo, para obtener el tercer Attribute, debe especificar myColl[2].

Consulte también

Se aplica a

Item[Type]

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

Obtiene el atributo que tiene el tipo especificado.

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

Parámetros

attributeType
Type

Tipo (Type) de Attribute que se va a obtener de la colección.

Valor de propiedad

Attribute que tiene el tipo especificado o, si el atributo no existe, el valor predeterminado del tipo de atributo.

Ejemplos

En el ejemplo de código siguiente se obtiene de DesignerAttribute la colección y se imprime su valor. Se supone que button1 y textBox1 se han creado en un formulario.

Para que se ejecute este ejemplo de código, debe proporcionar el nombre completo del ensamblado. Para obtener información sobre cómo obtener el nombre completo del ensamblado, vea Nombres de ensamblado.

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

Comentarios

Si el atributo no existe en la colección, esta propiedad devuelve el valor predeterminado para el tipo de atributo.

Consulte también

Se aplica a