AttributeCollection.Contains Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Определяет, имеет ли эта коллекция атрибутов указанный атрибут или массив атрибутов.
Перегрузки
| Имя | Описание |
|---|---|
| Contains(Attribute) |
Определяет, имеет ли эта коллекция атрибутов указанный атрибут. |
| Contains(Attribute[]) |
Определяет, содержит ли эта коллекция атрибутов все указанные атрибуты в массиве атрибутов. |
Contains(Attribute)
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
Определяет, имеет ли эта коллекция атрибутов указанный атрибут.
public:
bool Contains(Attribute ^ attribute);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public bool Contains(Attribute? attribute);
public bool Contains(Attribute attribute);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
member this.Contains : Attribute -> bool
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean
Параметры
Возвращаемое значение
true Значение , если коллекция содержит атрибут или является атрибутом по умолчанию для типа атрибута; falseв противном случае .
- Атрибуты
Примеры
В следующем примере кода проверяется, имеет BrowsableAttribute ли коллекция набор true. Предполагается, что button1 и textBox1 были созданы в форме.
protected:
void ContainsAttribute()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection^ attributes;
attributes = TypeDescriptor::GetAttributes( button1 );
// Sets an Attribute to the specific attribute.
BrowsableAttribute^ myAttribute = BrowsableAttribute::Yes;
if ( attributes->Contains( myAttribute ) )
{
textBox1->Text = "button1 has a browsable attribute.";
}
else
{
textBox1->Text = "button1 does not have a browsable attribute.";
}
}
private void ContainsAttribute() {
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection attributes;
attributes = TypeDescriptor.GetAttributes(button1);
// Sets an Attribute to the specific attribute.
BrowsableAttribute myAttribute = BrowsableAttribute.Yes;
if (attributes.Contains(myAttribute))
textBox1.Text = "button1 has a browsable attribute.";
else
textBox1.Text = "button1 does not have a browsable attribute.";
}
Private Sub ContainsAttribute
' Creates a new collection and assigns it the attributes for button.
Dim attributes As AttributeCollection
attributes = TypeDescriptor.GetAttributes(button1)
' Sets an Attribute to the specific attribute.
Dim myAttribute As BrowsableAttribute = BrowsableAttribute.Yes
If Attributes.Contains(myAttribute) Then
textBox1.Text = "button1 has a browsable attribute."
Else
textBox1.Text = "button1 does not have a browsable attribute."
End If
End Sub
Комментарии
Эта коллекция имеет указанный атрибут, если указанный тип атрибута существует в коллекции, и если значение указанного атрибута совпадает со значением экземпляра атрибута в коллекции.
Разница между Matches методами заключается Contains в том, что Matches вызывает Match метод для атрибута и Contains вызывает Equals метод.
Для большинства атрибутов эти методы выполняют то же самое. Однако для атрибутов, которые могут иметь несколько флагов, обычно реализуется таким образом, Match чтобы он возвращался true , если любой из флагов удовлетворен. Например, рассмотрим атрибут привязки данных с логическими флагами "SupportsSql", "SupportsOleDb" и "SupportsXml". Этот атрибут может присутствовать в свойстве, поддерживающем все три подхода к привязке данных. Это часто может быть так, что программист должен знать только в том случае, если конкретный подход доступен, а не все три. Таким образом, программист может использовать Match с экземпляром атрибута, содержащего только флаги, необходимые программисту.
См. также раздел
Применяется к
Contains(Attribute[])
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
Определяет, содержит ли эта коллекция атрибутов все указанные атрибуты в массиве атрибутов.
public:
bool Contains(cli::array <Attribute ^> ^ attributes);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public bool Contains(Attribute[]? attributes);
public bool Contains(Attribute[] attributes);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
member this.Contains : Attribute[] -> bool
member this.Contains : Attribute[] -> bool
Public Function Contains (attributes As Attribute()) As Boolean
Параметры
Возвращаемое значение
true Значение , если коллекция содержит все атрибуты; falseв противном случае .
- Атрибуты
Примеры
В следующем примере кода сравниваются атрибуты и button1textBox1 проверяется, содержатся ли атрибуты кнопки в атрибутах текстового поля. Предполагается, что оба button1 и textBox1 были созданы в форме.
private:
void ContainsAttributes()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection^ myCollection;
myCollection = TypeDescriptor::GetAttributes( button1 );
// Checks to see whether the attributes in myCollection are the attributes for textBox1.
array<Attribute^>^ myAttrArray = gcnew array<Attribute^>(100);
TypeDescriptor::GetAttributes( textBox1 )->CopyTo( myAttrArray, 0 );
if ( myCollection->Contains( myAttrArray ) )
{
textBox1->Text = "Both the button and text box have the same attributes.";
}
else
{
textBox1->Text = "The button and the text box do not have the same attributes.";
}
}
private void ContainsAttributes() {
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection myCollection;
myCollection = TypeDescriptor.GetAttributes(button1);
// Checks to see whether the attributes in myCollection are the attributes for textBox1.
Attribute[] myAttrArray = new Attribute[100];
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
if (myCollection.Contains(myAttrArray))
textBox1.Text = "Both the button and text box have the same attributes.";
else
textBox1.Text = "The button and the text box do not have the same attributes.";
}
Private Sub ContainsAttributes()
' Creates a new collection and assigns it the attributes for button1.
Dim myCollection As AttributeCollection
myCollection = TypeDescriptor.GetAttributes(button1)
' Checks to see whether the attributes in myCollection are the attributes for textBox1.
Dim myAttrArray(100) As Attribute
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
If myCollection.Contains(myAttrArray) Then
textBox1.Text = "Both the button and text box have the same attributes."
Else
textBox1.Text = "The button and the text box do not have the same attributes."
End If
End Sub
Комментарии
Эта коллекция содержит указанный массив атрибутов, если все указанные типы атрибутов существуют в коллекции, а если каждый атрибут в указанном массиве совпадает с атрибутом в коллекции.