AttributeCollection.Item[] Свойство

Определение

Возвращает атрибут с указанным индексом.

Перегрузки

Имя Описание
Item[Int32]

Возвращает атрибут с указанным номером индекса.

Item[Type]

Возвращает атрибут с указанным типом.

Item[Int32]

Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs

Возвращает атрибут с указанным номером индекса.

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

Параметры

index
Int32

Отсчитываемый от нуля индекс AttributeCollection.

Значение свойства

С Attribute указанным номером индекса.

Примеры

В следующем примере кода свойство используется Item[] для печати имени указанного Attribute номером индекса в текстовом поле. Так как номер индекса основан на нулях, в этом примере кода выводится имя второго Attribute в текстовом поле. Предполагается, что он создан button1 и textBox1 создан на форме.

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

Комментарии

Номер индекса равен нулю. Таким образом, необходимо вычитать 1 из числового положения конкретной, Attribute чтобы получить доступ к этому Attribute. Например, чтобы получить третий Attribute, необходимо указать myColl[2].

См. также раздел

Применяется к

Item[Type]

Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs
Исходный код:
AttributeCollection.cs

Возвращает атрибут с указанным типом.

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

Параметры

attributeType
Type

Type Получение Attribute из коллекции.

Значение свойства

Значение Attribute по умолчанию для указанного типа или, если атрибут не существует, значение по умолчанию для типа атрибута.

Примеры

В следующем примере кода извлекается DesignerAttribute из коллекции и выводится его значение. Предполагается, что button1 и textBox1 были созданы в форме.

Для выполнения этого примера кода необходимо указать полное имя сборки. Сведения о том, как получить полное имя сборки, см. в разделе "Имена сборок".

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

Комментарии

Если атрибут не существует в коллекции, это свойство возвращает значение по умолчанию для типа атрибута.

См. также раздел

Применяется к