AttributeCollection.Matches Metoda

Definicja

Określa, czy określony atrybut lub tablica atrybutów jest taka sama jak atrybut lub tablica atrybutów w kolekcji.

Przeciążenia

Matches(Attribute)

Określa, czy określony atrybut jest taki sam jak atrybut w kolekcji.

Matches(Attribute[])

Określa, czy atrybuty w określonej tablicy są takie same jak atrybuty w kolekcji.

Matches(Attribute)

Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs

Określa, czy określony atrybut jest taki sam jak atrybut w kolekcji.

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

Wystąpienie do Attribute porównania z atrybutami w tej kolekcji.

Zwraca

true jeśli atrybut znajduje się w kolekcji i ma taką samą wartość jak atrybut w kolekcji; w przeciwnym razie , false.

Przykłady

Poniższy przykład kodu sprawdza, czy BrowsableAttribute element jest członkiem kolekcji i że został ustawiony na truewartość . Przyjęto założenie, że button1 i textBox1 zostały utworzone w formularzu.

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

Uwagi

Atrybut może zapewnić obsługę dopasowywania.

Różnica między metodami Matches i Contains polega Matches na wywołaniu Match metody na atrybucie i Contains wywołaniu Equals metody .

W przypadku większości atrybutów te metody robią to samo. W przypadku atrybutów, które mogą mieć wiele flag, jest jednak zwykle implementowane, Match aby zwracać true , jeśli którakolwiek z flag jest spełniona. Rozważmy na przykład atrybut powiązania danych z flagami logicznymi "SupportsSql", "SupportsOleDb" i "SupportsXml". Ten atrybut może być obecny we właściwości obsługującej wszystkie trzy podejścia powiązania danych. Często zdarza się, że programista musi wiedzieć tylko wtedy, gdy jest dostępne konkretne podejście, a nie wszystkie trzy. W związku z tym programista może używać Match z wystąpieniem atrybutu zawierającego tylko flagi, których potrzebuje programista.

Zobacz też

Dotyczy

Matches(Attribute[])

Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs
Źródło:
AttributeCollection.cs

Określa, czy atrybuty w określonej tablicy są takie same jak atrybuty w kolekcji.

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[]

Tablica do MemberAttributes porównania z atrybutami w tej kolekcji.

Zwraca

true jeśli wszystkie atrybuty w tablicy znajdują się w kolekcji i mają te same wartości co atrybuty w kolekcji; w przeciwnym razie , false.

Przykłady

Poniższy przykład kodu porównuje atrybuty w przycisku i polu tekstowym, aby sprawdzić, czy są zgodne. Przyjęto założenie, że button1 i textBox1 zostały utworzone w formularzu.

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

Uwagi

Atrybut może zapewnić obsługę dopasowywania.

Zobacz też

Dotyczy