AttributeCollection.Matches Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Определяет, совпадает ли указанный атрибут или массив атрибутов с атрибутом или массивом атрибутов в коллекции.
Перегрузки
| Имя | Описание |
|---|---|
| Matches(Attribute) |
Определяет, совпадает ли указанный атрибут с атрибутом в коллекции. |
| Matches(Attribute[]) |
Определяет, совпадают ли атрибуты в указанном массиве с атрибутами в коллекции. |
Matches(Attribute)
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
Определяет, совпадает ли указанный атрибут с атрибутом в коллекции.
public:
bool Matches(Attribute ^ attribute);
public bool Matches(Attribute? attribute);
public bool Matches(Attribute attribute);
member this.Matches : Attribute -> bool
Public Function Matches (attribute As Attribute) As Boolean
Параметры
Возвращаемое значение
true Значение атрибута, если атрибут содержится в коллекции и имеет то же значение, что и атрибут в коллекции; falseв противном случае .
Примеры
В следующем примере кода проверяется, является ли BrowsableAttribute он членом коллекции и имеет значение true. Предполагается, что button1 и textBox1 были созданы в форме.
private:
void MatchesAttribute()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection^ attributes;
attributes = TypeDescriptor::GetAttributes( button1 );
// Checks to see if the browsable attribute is true.
if ( attributes->Matches( BrowsableAttribute::Yes ) )
{
textBox1->Text = "button1 is browsable.";
}
else
{
textBox1->Text = "button1 is not browsable.";
}
}
private void MatchesAttribute() {
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection attributes;
attributes = TypeDescriptor.GetAttributes(button1);
// Checks to see if the browsable attribute is true.
if (attributes.Matches(BrowsableAttribute.Yes))
textBox1.Text = "button1 is browsable.";
else
textBox1.Text = "button1 is not browsable.";
}
Private Sub MatchesAttribute
' Creates a new collection and assigns it the attributes for button
Dim attributes As AttributeCollection
attributes = TypeDescriptor.GetAttributes(button1)
' Checks to see if the browsable attribute is true.
If attributes.Matches(BrowsableAttribute.Yes) Then
textBox1.Text = "button1 is browsable."
Else
textBox1.Text = "button1 is not browsable."
End If
End Sub
Комментарии
Атрибут может обеспечить поддержку сопоставления.
Разница между Matches методами заключается Contains в том, что Matches вызывает Match метод для атрибута и Contains вызывает Equals метод.
Для большинства атрибутов эти методы выполняют то же самое. Однако для атрибутов, которые могут иметь несколько флагов, обычно реализуется таким образом, Match чтобы он возвращался true , если любой из флагов удовлетворен. Например, рассмотрим атрибут привязки данных с логическими флагами "SupportsSql", "SupportsOleDb" и "SupportsXml". Этот атрибут может присутствовать в свойстве, поддерживающем все три подхода к привязке данных. Это часто может быть так, что программист должен знать только в том случае, если конкретный подход доступен, а не все три. Таким образом, программист может использовать Match с экземпляром атрибута, содержащего только флаги, необходимые программисту.
См. также раздел
Применяется к
Matches(Attribute[])
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
- Исходный код:
- AttributeCollection.cs
Определяет, совпадают ли атрибуты в указанном массиве с атрибутами в коллекции.
public:
bool Matches(cli::array <Attribute ^> ^ attributes);
public bool Matches(Attribute[]? attributes);
public bool Matches(Attribute[] attributes);
member this.Matches : Attribute[] -> bool
Public Function Matches (attributes As Attribute()) As Boolean
Параметры
- attributes
- Attribute[]
Массив для MemberAttributes сравнения с атрибутами в этой коллекции.
Возвращаемое значение
true Значение , если все атрибуты в массиве содержатся в коллекции и имеют те же значения, что и атрибуты в коллекции; falseв противном случае .
Примеры
В следующем примере кода сравниваются атрибуты в кнопке и текстовом поле, чтобы узнать, совпадают ли они. Предполагается, что button1 и textBox1 были созданы в форме.
private:
void MatchesAttributes()
{
// 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 match the attributes for textBox1.
array<Attribute^>^ myAttrArray = gcnew array<Attribute^>(100);
TypeDescriptor::GetAttributes( textBox1 )->CopyTo( myAttrArray, 0 );
if ( myCollection->Matches( myAttrArray ) )
{
textBox1->Text = "The attributes in the button and text box match.";
}
else
{
textBox1->Text = "The attributes in the button and text box do not match.";
}
}
private void MatchesAttributes() {
// 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 match the attributes for textBox1.
Attribute[] myAttrArray = new Attribute[100];
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
if (myCollection.Matches(myAttrArray))
textBox1.Text = "The attributes in the button and text box match.";
else
textBox1.Text = "The attributes in the button and text box do not match.";
}
Private Sub MatchesAttributes()
' 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 match the attributes.
' for textBox1.
Dim myAttrArray(100) As Attribute
TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
If myCollection.Matches(myAttrArray) Then
textBox1.Text = "The attributes in the button and text box match."
Else
textBox1.Text = "The attributes in the button and text box do not match."
End If
End Sub
Комментарии
Атрибут может обеспечить поддержку сопоставления.