AttributeCollection.Contains Metódus

Definíció

Meghatározza, hogy az attribútumgyűjtemény rendelkezik-e a megadott attribútummal vagy attribútumtömbbel.

Túlterhelések

Name Description
Contains(Attribute)

Meghatározza, hogy az attribútumgyűjtemény rendelkezik-e a megadott attribútummal.

Contains(Attribute[])

Meghatározza, hogy ez az attribútumgyűjtemény tartalmazza-e az attribútumtömb összes megadott attribútumát.

Contains(Attribute)

Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs

Meghatározza, hogy az attribútumgyűjtemény rendelkezik-e a megadott attribútummal.

public:
 bool Contains(Attribute ^ attribute);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public bool Contains(Attribute? attribute);
public bool Contains(Attribute attribute);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
member this.Contains : Attribute -> bool
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean

Paraméterek

attribute
Attribute

A Attribute gyűjteményben keresendő.

Válaszok

trueha a gyűjtemény tartalmazza az attribútumot, vagy az attribútum típusának alapértelmezett attribútuma; egyéb esetben. false

Attribútumok

Példák

Az alábbi példakód ellenőrzi, hogy a gyűjtemény rendelkezik-e BrowsableAttribute beállított értékekkel true. Ezt feltételezi, button1 és textBox1 egy űrlapon lett létrehozva.

protected:
   void ContainsAttribute()
   {
      // Creates a new collection and assigns it the attributes for button1.
      AttributeCollection^ attributes;
      attributes = TypeDescriptor::GetAttributes( button1 );
      
      // Sets an Attribute to the specific attribute.
      BrowsableAttribute^ myAttribute = BrowsableAttribute::Yes;

      if ( attributes->Contains( myAttribute ) )
      {
         textBox1->Text = "button1 has a browsable attribute.";
      }
      else
      {
         textBox1->Text = "button1 does not have a browsable attribute.";
      }
   }
private void ContainsAttribute() {
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);

    // Sets an Attribute to the specific attribute.
    BrowsableAttribute myAttribute = BrowsableAttribute.Yes;

    if (attributes.Contains(myAttribute))
       textBox1.Text = "button1 has a browsable attribute.";
    else
       textBox1.Text = "button1 does not have a browsable attribute.";
 }
Private Sub ContainsAttribute
    ' Creates a new collection and assigns it the attributes for button.
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)

    ' Sets an Attribute to the specific attribute.
    Dim myAttribute As BrowsableAttribute = BrowsableAttribute.Yes

    If Attributes.Contains(myAttribute) Then
        textBox1.Text = "button1 has a browsable attribute."
    Else
        textBox1.Text = "button1 does not have a browsable attribute."
    End If
End Sub

Megjegyzések

Ez a gyűjtemény rendelkezik a megadott attribútummal, ha a megadott attribútumtípus létezik a gyűjteményben, és ha a megadott attribútum értéke megegyezik a gyűjteményben lévő attribútum példányának értékével.

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:

Contains(Attribute[])

Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs
Forrás:
AttributeCollection.cs

Meghatározza, hogy ez az attribútumgyűjtemény tartalmazza-e az attribútumtömb összes megadott attribútumát.

public:
 bool Contains(cli::array <Attribute ^> ^ attributes);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public bool Contains(Attribute[]? attributes);
public bool Contains(Attribute[] attributes);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
member this.Contains : Attribute[] -> bool
member this.Contains : Attribute[] -> bool
Public Function Contains (attributes As Attribute()) As Boolean

Paraméterek

attributes
Attribute[]

A gyűjteményben keresendő típustömb Attribute .

Válaszok

trueha a gyűjtemény tartalmazza az összes attribútumot; egyéb esetben. false

Attribútumok

Példák

Az alábbi példakód összehasonlítja a gomb attribútumait button1 , és textBox1 ellenőrzi, hogy a gomb attribútumai szerepelnek-e a szövegmező attribútumaiban. Feltételezi, hogy mindkettőt button1textBox1 egy űrlapon hozták létre.

private:
   void ContainsAttributes()
   {
      // 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 are the attributes for textBox1.
      array<Attribute^>^ myAttrArray = gcnew array<Attribute^>(100);
      TypeDescriptor::GetAttributes( textBox1 )->CopyTo( myAttrArray, 0 );
      if ( myCollection->Contains( myAttrArray ) )
      {
         textBox1->Text = "Both the button and text box have the same attributes.";
      }
      else
      {
         textBox1->Text = "The button and the text box do not have the same attributes.";
      }
   }
private void ContainsAttributes() {
   // 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 are the attributes for textBox1.
   Attribute[] myAttrArray = new Attribute[100];
   TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
   if (myCollection.Contains(myAttrArray))
      textBox1.Text = "Both the button and text box have the same attributes.";
   else
      textBox1.Text = "The button and the text box do not have the same attributes.";
}
Private Sub ContainsAttributes()
    ' 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 are the attributes for textBox1.
    Dim myAttrArray(100) As Attribute
    TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0)
    If myCollection.Contains(myAttrArray) Then
        textBox1.Text = "Both the button and text box have the same attributes."
    Else
        textBox1.Text = "The button and the text box do not have the same attributes."
    End If
End Sub

Megjegyzések

Ez a gyűjtemény rendelkezik a megadott attribútumtömbbel, ha az összes megadott attribútumtípus létezik a gyűjteményben, és ha a megadott tömb minden attribútuma megegyezik a gyűjtemény egyik attribútumával.

Lásd még

A következőre érvényes: