AttributeCollection.Matches Metoda

Definice

Určuje, zda zadaný atribut nebo pole atributů je stejný jako atribut nebo pole atributů v kolekci.

Přetížení

Name Description
Matches(Attribute)

Určuje, zda je zadaný atribut stejný jako atribut v kolekci.

Matches(Attribute[])

Určuje, zda jsou atributy v zadaném poli stejné jako atributy v kolekci.

Matches(Attribute)

Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs

Určuje, zda je zadaný atribut stejný jako atribut v kolekci.

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

Parametry

attribute
Attribute

Instance Attribute porovnání s atributy v této kolekci.

Návraty

truepokud je atribut obsažen v kolekci a má stejnou hodnotu jako atribut v kolekci; v opačném případě . false

Příklady

Následující příklad kódu ověří, že BrowsableAttribute je členem kolekce a že je nastaven na true. Předpokládá, že button1 a textBox1 byly vytvořeny ve formuláři.

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

Poznámky

Atribut může poskytovat podporu pro porovnávání.

Rozdíl mezi metodami Matches a Contains metodami je, že Matches volá metodu Match atributu a Contains volá metodu Equals .

U většiny atributů tyto metody dělají totéž. U atributů, které mohou mít více příznaků, je však obvykle implementováno, aby se vrátilaMatch, true pokud jsou některé z příznaků splněny. Představte si například atribut datové vazby s logickými příznaky "SupportsSql", "SupportsOleDb" a "SupportsXml". Tento atribut může být k dispozici u vlastnosti, která podporuje všechny tři přístupy k datovým vazbě. Často se stává, že programátor potřebuje vědět pouze v případě, že je k dispozici konkrétní přístup, ne všechny tři. Programátor by proto mohl použít Match s instancí atributu, který obsahuje pouze příznaky, které programátor potřebuje.

Viz také

Platí pro

Matches(Attribute[])

Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs
Zdroj:
AttributeCollection.cs

Určuje, zda jsou atributy v zadaném poli stejné jako atributy v kolekci.

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

Parametry

attributes
Attribute[]

Pole, které MemberAttributes se má porovnat s atributy v této kolekci.

Návraty

truepokud jsou všechny atributy v poli obsaženy v kolekci a mají stejné hodnoty jako atributy v kolekci; v opačném případě . false

Příklady

Následující příklad kódu porovnává atributy v tlačítku a textovém poli, abyste viděli, jestli se shodují. Předpokládá, že button1 a textBox1 byly vytvořeny ve formuláři.

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

Poznámky

Atribut může poskytovat podporu pro porovnávání.

Viz také

Platí pro