AttributeCollection.Contains Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Determina se questa raccolta di attributi ha l'attributo o la matrice di attributi specificati.
Overload
| Nome | Descrizione |
|---|---|
| Contains(Attribute) |
Determina se questa raccolta di attributi ha l'attributo specificato. |
| Contains(Attribute[]) |
Determina se questa raccolta di attributi contiene tutti gli attributi specificati nella matrice di attributi. |
Contains(Attribute)
Determina se questa raccolta di attributi ha l'attributo specificato.
public:
bool Contains(Attribute ^ attribute);
public bool Contains(Attribute attribute);
member this.Contains : Attribute -> bool
Public Function Contains (attribute As Attribute) As Boolean
Parametri
Valori restituiti
true se la raccolta contiene l'attributo o è l'attributo predefinito per il tipo di attributo; in caso contrario, false.
Esempio
Nell'esempio di codice seguente viene verificato se la raccolta è BrowsableAttribute impostata su true. Si presuppone che button1 e textBox1 siano stati creati in un modulo.
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
Commenti
Questa raccolta ha l'attributo specificato se il tipo specificato di attributo esiste nella raccolta e se il valore dell'attributo specificato è uguale al valore dell'istanza dell'attributo nell'insieme.
La differenza tra i Matches metodi e Contains è che Matches chiama il Match metodo su un attributo e Contains chiama il Equals metodo .
Per la maggior parte degli attributi, questi metodi eseguono la stessa operazione. Per gli attributi che possono avere più flag, tuttavia, Match viene in genere implementato in modo che restituisca true se uno dei flag è soddisfatto. Si consideri ad esempio un attributo di data binding con i flag booleani "SupportsSql", "SupportsOleDb" e "SupportsXml". Questo attributo può essere presente in una proprietà che supporta tutti e tre gli approcci di data binding. Spesso sarà il caso che un programmatore debba sapere solo se è disponibile un particolare approccio, 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
Contains(Attribute[])
Determina se questa raccolta di attributi contiene tutti gli attributi specificati nella matrice di attributi.
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
Parametri
Valori restituiti
true se la raccolta contiene tutti gli attributi; in caso contrario, false.
Esempio
Nell'esempio di codice seguente vengono confrontati gli attributi in button1 e textBox1 per verificare se gli attributi per il pulsante sono contenuti negli attributi per la casella di testo. Si presuppone che sia button1 che textBox1 siano stati creati in un modulo.
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
Commenti
Questa raccolta ha la matrice di attributi specificata se tutti i tipi di attributo specificati sono presenti nella raccolta e se ogni attributo nella matrice specificata è uguale a un attributo nella raccolta.