AttributeCollection.Matches Metodo

Definizione

Consente di determinare se un attributo o una matrice di attributi specificata coincidono con l'attributo o la matrice di attributi presenti nell'insieme.

Overload

Matches(Attribute)

Consente di determinare se un attributo specificato è uguale a un attributo nell'insieme.

Matches(Attribute[])

Consente di determinare se gli attributi nella matrice specificata sono uguali agli attributi dell'insieme.

Matches(Attribute)

Source:
AttributeCollection.cs
Source:
AttributeCollection.cs
Source:
AttributeCollection.cs

Consente di determinare se un attributo specificato è uguale a un attributo nell'insieme.

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

Parametri

attribute
Attribute

Istanza di Attribute da confrontare con gli attributi in questo insieme.

Restituisce

true se l'attributo è contenuto nell'insieme e presenta lo stesso valore dell'attributo nell'insieme. In caso contrario, false.

Esempio

Nell'esempio di codice seguente viene verificato che l'oggetto BrowsableAttribute è un membro dell'insieme e che sia stato impostato su true. Si presuppone che button1 e textBox1 siano stati creati in un modulo.

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

Commenti

Un attributo può fornire supporto per la corrispondenza.

La differenza tra i Matches metodi e Contains è che Matches chiama il Match metodo in un attributo e Contains chiama il Equals metodo.

Per la maggior parte degli attributi, questi metodi fanno la stessa cosa. Per gli attributi che possono avere più flag, tuttavia, Match viene in genere implementato in modo che restituisca true se uno dei flag viene soddisfatto. Si consideri ad esempio un attributo di data binding con i flag booleani "SupportSql", "SupportOleDb" e "SupportXml". Questo attributo può essere presente in una proprietà che supporta tutti e tre gli approcci di associazione dati. Spesso sarà il caso che un programmatore debba sapere solo se è disponibile un approccio specifico, non tutti e tre. Pertanto, un programmatore può usare Match con un'istanza dell'attributo contenente solo i flag necessari per il programmatore.

Vedi anche

Si applica a

Matches(Attribute[])

Source:
AttributeCollection.cs
Source:
AttributeCollection.cs
Source:
AttributeCollection.cs

Consente di determinare se gli attributi nella matrice specificata sono uguali agli attributi dell'insieme.

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

Parametri

attributes
Attribute[]

Matrice di MemberAttributes da confrontare con gli attributi in questo insieme.

Restituisce

true se tutti gli attributi della matrice sono contenuti nell'insieme e presentano gli stessi valori degli attributi nell'insieme. In caso contrario, false.

Esempio

Nell'esempio di codice seguente vengono confrontati gli attributi in un pulsante e una casella di testo per verificare se corrispondono. Si presuppone che button1 e textBox1 siano stati creati in un modulo.

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

Commenti

Un attributo può fornire supporto per la corrispondenza.

Vedi anche

Si applica a