AttributeCollection.Item[] Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o atributo com o índice especificado.
Sobrecargas
| Name | Description |
|---|---|
| Item[Int32] |
Obtém o atributo com o número de índice especificado. |
| Item[Type] |
Obtém o atributo com o tipo especificado. |
Item[Int32]
Obtém o atributo com o 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
O índice baseado em zero de AttributeCollection.
Valor de Propriedade
O Attribute com o número de índice especificado.
Exemplos
O seguinte exemplo de código usa a Item[] propriedade para imprimir o nome especificado Attribute pelo número de índice numa caixa de texto. Como o número de índice é baseado em zero, este exemplo de código imprime o nome do segundo Attribute numa caixa de texto. Assume button1 e textBox1 foi criado num formulário.
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
Observações
O número do índice é baseado em zero. Portanto, deve subtrair 1 da posição numérica de um particular Attribute para aceder a esse Attribute. Por exemplo, para obter o terceiro Attribute, precisa de especificar myColl[2].
Ver também
Aplica-se a
Item[Type]
Obtém o atributo com o tipo especificado.
public:
virtual property Attribute ^ default[Type ^] { Attribute ^ get(Type ^ attributeType); };
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
Valor de Propriedade
O Attribute com o tipo especificado ou, se o atributo não existir, o valor padrão para o tipo de atributo.
Exemplos
O seguinte exemplo de código obtém o DesignerAttribute da coleção e imprime o seu valor. Assume que button1 e textBox1 foram criados numa forma.
Para que este exemplo de código seja executado, deve fornecer o nome de assembleia totalmente qualificado. Para informações sobre como obter o nome de assembleia totalmente qualificado, consulte Nomes de Assembleia.
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
Observações
Se o atributo não existir na coleção, esta propriedade devolve o valor padrão para o tipo de atributo.