AttributeCollection.Contains Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Détermine si cette collection d’attributs a l’attribut spécifié ou le tableau d’attributs.
Surcharges
| Nom | Description |
|---|---|
| Contains(Attribute) |
Détermine si cette collection d’attributs a l’attribut spécifié. |
| Contains(Attribute[]) |
Détermine si cette collection d’attributs contient tous les attributs spécifiés dans le tableau d’attributs. |
Contains(Attribute)
Détermine si cette collection d’attributs a l’attribut spécifié.
public:
bool Contains(Attribute ^ attribute);
public bool Contains(Attribute attribute);
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean
Paramètres
Retours
true si la collection contient l’attribut ou est l’attribut par défaut pour le type d’attribut ; sinon, false.
Exemples
L’exemple de code suivant vérifie si la collection a une BrowsableAttribute valeur définie truesur . Il part du principe que button1 et textBox1 ont été créés sur un formulaire.
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
Remarques
Cette collection a l’attribut spécifié si le type d’attribut spécifié existe dans la collection et si la valeur de l’attribut spécifié est identique à la valeur de l’instance de l’attribut dans la collection.
La différence entre les méthodes et Contains les Matches méthodes consiste à Matches appeler la Match méthode sur un attribut et Contains à appeler la Equals méthode.
Pour la plupart des attributs, ces méthodes font la même chose. Pour les attributs qui peuvent avoir plusieurs indicateurs, toutefois, Match est généralement implémenté afin qu’il retourne true si l’un des indicateurs est satisfait. Par exemple, considérez un attribut de liaison de données avec les indicateurs booléens « SupportsSql », « SupportsOleDb » et « SupportsXml ». Cet attribut peut être présent sur une propriété qui prend en charge les trois approches de liaison de données. Il sera souvent le cas qu’un programmeur doit savoir uniquement si une approche particulière est disponible, pas les trois. Par conséquent, un programmeur peut utiliser Match avec une instance de l’attribut contenant uniquement les indicateurs dont le programmeur a besoin.
Voir aussi
S’applique à
Contains(Attribute[])
Détermine si cette collection d’attributs contient tous les attributs spécifiés dans le tableau d’attributs.
public:
bool Contains(cli::array <Attribute ^> ^ attributes);
public bool Contains(Attribute[] attributes);
member this.Contains : Attribute[] -> bool
Public Function Contains (attributes As Attribute()) As Boolean
Paramètres
Retours
true si la collection contient tous les attributs ; sinon, false.
Exemples
L’exemple de code suivant compare les attributs et button1textBox1 vérifie si les attributs du bouton sont contenus dans les attributs de la zone de texte. Il part du principe que les deux button1 et textBox1 ont été créés sur un formulaire.
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
Remarques
Cette collection a le tableau d’attributs spécifié si tous les types d’attributs spécifiés existent dans la collection et si chaque attribut du tableau spécifié est le même qu’un attribut dans la collection.