Share via


AttributeCollection.Matches Metoda

Definice

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

Přetížení

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

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 pro 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ěřuje, že BrowsableAttribute je členem kolekce a že byl 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 párování.

Rozdíl mezi metodami a Contains spočívá v Matches tom, že Matches volá metodu Match na atributu a Contains volá metoduEquals.

U většiny atributů tyto metody dělají totéž. Pro atributy, které mohou mít více příznaků, je však obvykle implementována tak, Match aby se vrátila 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 přítomen u vlastnosti, která podporuje všechny tři přístupy k datovým vazbě. Často se stane, že programátor potřebuje vědět jenom to, jestli je k dispozici konkrétní přístup, ne všechny tři. Proto programátor může použít Match s instancí atributu obsahující pouze příznaky, které programátor potřebuje.

Viz také

Platí pro

Matches(Attribute[])

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 MemberAttributes pro porovnání 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 a zjišťuje, 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 párování.

Viz také

Platí pro