AttributeCollection.Matches Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Meghatározza, hogy egy megadott attribútum vagy attribútumtömb megegyezik-e a gyűjtemény attribútumainak vagy tömbjének attribútumaival.
Túlterhelések
| Name | Description |
|---|---|
| Matches(Attribute) |
Meghatározza, hogy egy megadott attribútum megegyezik-e a gyűjtemény egyik attribútumával. |
| Matches(Attribute[]) |
Meghatározza, hogy a megadott tömb attribútumai megegyeznek-e a gyűjtemény attribútumaival. |
Matches(Attribute)
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
Meghatározza, hogy egy megadott attribútum megegyezik-e a gyűjtemény egyik attribútumával.
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
Paraméterek
Válaszok
trueha az attribútum a gyűjteményben található, és ugyanazzal az értékkel rendelkezik, mint a gyűjteményben lévő attribútum; egyéb esetben. false
Példák
Az alábbi példakód ellenőrzi, hogy a BrowsableAttribute gyűjtemény tagja-e, és hogy be van-e állítva true. Ezt feltételezi, button1 és textBox1 egy űrlapon lett létrehozva.
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
Megjegyzések
Az attribútumok támogathatják az egyeztetést.
A metódusok és a Matches metódusok közötti különbség az, hogy Contains egy attribútumon hívja meg a Matches metódust, és Match meghívja a metódustContains.Equals
A legtöbb attribútum esetében ezek a metódusok ugyanezt teszik. Az olyan attribútumok esetében, amelyek több jelölőt is tartalmazhatnak, általában úgy vannak implementálva, Match hogy az visszaadja true , ha a jelzők bármelyike teljesül. Vegyük például a "SupportsSql", a "SupportsOleDb" és a "SupportsXml" logikai jelzőkkel rendelkező adatkötési attribútumot. Ez az attribútum olyan tulajdonságon lehet jelen, amely mindhárom adatkötési módszert támogatja. Gyakran előfordul, hogy a programozónak csak akkor kell tudnia, ha egy adott megközelítés elérhető, nem mindhárom. Ezért a programozó használhatja Match az attribútum egy példányát, amely csak azokat a jelzőket tartalmazza, amelyekre a programozónak szüksége van.
Lásd még
A következőre érvényes:
Matches(Attribute[])
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
- Forrás:
- AttributeCollection.cs
Meghatározza, hogy a megadott tömb attribútumai megegyeznek-e a gyűjtemény attribútumaival.
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
Paraméterek
- attributes
- Attribute[]
A gyűjtemény attribútumaival összehasonlítandó tömb MemberAttributes .
Válaszok
trueha a tömb összes attribútuma szerepel a gyűjteményben, és azonos értékekkel rendelkeznek, mint a gyűjtemény attribútumai; egyéb esetben. false
Példák
Az alábbi példa egy gomb és egy szövegmező attribútumait hasonlítja össze annak megállapításához, hogy egyeznek-e. Ezt feltételezi, button1 és textBox1 egy űrlapon lett létrehozva.
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
Megjegyzések
Az attribútumok támogathatják az egyeztetést.