AttributeCollection.Contains Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Určuje, zda má tato kolekce atributů zadaný atribut nebo pole atributů.
Přetížení
| Name | Description |
|---|---|
| Contains(Attribute) |
Určuje, zda má tato kolekce atributů zadaný atribut. |
| Contains(Attribute[]) |
Určuje, zda tato kolekce atributů obsahuje všechny zadané atributy v poli atributů. |
Contains(Attribute)
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
Určuje, zda má tato kolekce atributů zadaný atribut.
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
Parametry
Návraty
truepokud kolekce obsahuje atribut nebo je výchozím atributem pro typ atributu; v opačném případě . false
- Atributy
Příklady
Následující příklad kódu zkontroluje, zda kolekce má nastavenou BrowsableAttribute hodnotu true. Předpokládá, že button1 a textBox1 byly vytvořeny ve formuláři.
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
Poznámky
Tato kolekce má zadaný atribut, pokud zadaný typ atributu existuje v kolekci a pokud hodnota zadaného atributu je stejná jako hodnota instance atributu v kolekci.
Rozdíl mezi metodami Matches a Contains metodami je, že Matches volá metodu Match atributu a Contains volá metodu Equals .
U většiny atributů tyto metody dělají totéž. U atributů, které mohou mít více příznaků, je však obvykle implementováno, aby se vrátilaMatch, true pokud jsou některé z příznaků splněny. Představte si například atribut datové vazby s logickými příznaky "SupportsSql", "SupportsOleDb" a "SupportsXml". Tento atribut může být k dispozici u vlastnosti, která podporuje všechny tři přístupy k datovým vazbě. Často se stává, že programátor potřebuje vědět pouze v případě, že je k dispozici konkrétní přístup, ne všechny tři. Programátor by proto mohl použít Match s instancí atributu, který obsahuje pouze příznaky, které programátor potřebuje.
Viz také
Platí pro
Contains(Attribute[])
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
- Zdroj:
- AttributeCollection.cs
Určuje, zda tato kolekce atributů obsahuje všechny zadané atributy v poli atributů.
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
Parametry
Návraty
truepokud kolekce obsahuje všechny atributy; v opačném případě . false
- Atributy
Příklady
Následující příklad kódu porovná atributy v button1 a textBox1 zjistí, zda jsou atributy tlačítka obsaženy v atributech textového pole. Předpokládá se, že ve formuláři byly vytvořeny obě button1 a textBox1 byly vytvořeny.
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
Poznámky
Tato kolekce obsahuje zadanou matici atributů, pokud v kolekci existují všechny zadané typy atributů a pokud je každý atribut v zadaném poli stejný jako atribut v kolekci.