Freigeben über


PropertyDescriptorCollection-Klasse

Stellt eine Auflistung von PropertyDescriptor-Objekten dar.

Namespace: System.ComponentModel
Assembly: System (in system.dll)

Syntax

'Declaration
Public Class PropertyDescriptorCollection
    Implements IList, IDictionary, ICollection, IEnumerable
'Usage
Dim instance As PropertyDescriptorCollection
public class PropertyDescriptorCollection : IList, IDictionary, ICollection, 
    IEnumerable
public ref class PropertyDescriptorCollection : IList, IDictionary, ICollection, 
    IEnumerable
public class PropertyDescriptorCollection implements IList, IDictionary, 
    ICollection, IEnumerable
public class PropertyDescriptorCollection implements IList, IDictionary, 
    ICollection, IEnumerable

Hinweise

PropertyDescriptorCollection ist schreibgeschützt und implementiert keine Methoden zum Hinzufügen oder Entfernen von Eigenschaften. Sie müssen diese Klasse vererben, um diese Methoden zu implementieren.

Den Inhalt der Auflistung können Sie mithilfe der in der PropertyDescriptorCollection-Klasse verfügbaren Eigenschaften abfragen. Mit der Count-Eigenschaft können Sie die Anzahl der Elemente in der Auflistung bestimmen. Mit der Item-Eigenschaft können Sie eine bestimmte Eigenschaft nach Indexnummer oder Namen abrufen.

Neben den Eigenschaften können Sie auch die Find-Methode verwenden, um eine Beschreibung der Eigenschaft mit dem angegebenen Namen aus der Auflistung abzurufen.

Hinweis

Das auf diese Klasse angewendete HostProtectionAttribute-Attribut besitzt den Resources-Eigenschaftenwert Synchronization. Das HostProtectionAttribute hat keine Auswirkungen auf Desktopanwendungen (die normalerweise durch Doppelklicken auf ein Symbol, Eingeben eines Befehls oder eines URL in einem Browser gestartet werden). Weitere Informationen finden Sie unter der HostProtectionAttribute-Klasse oder unter SQL Server-Programmierung und Hostschutzattribute.

Beispiel

Im folgenden Codebeispiel wird unter Verwendung der Eigenschaften von button1 eine neue PropertyDescriptorCollection-Klasse erstellt. Dafür ist es erforderlich, dass button1 in einem Formular instanziiert wurde.

Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
PropertyDescriptorCollection properties = 
    TypeDescriptor.GetProperties(button1);

Im nächsten Beispiel werden sämtliche Eigenschaften in einem Textfeld auf einer Schaltfläche ausgegeben. Dafür ist es erforderlich, dass button1 und textBox1 in einem Formular instanziiert wurden.

Private Sub MyPropertyCollection()
    ' Creates a new collection and assign it the properties for button1.
    Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
    
    ' Displays each property in the collection in a text box.
    Dim myProperty As PropertyDescriptor
    For Each myProperty In  properties
        textBox1.Text &= myProperty.Name & ControlChars.Cr
    Next myProperty
End Sub 'MyPropertyCollection 
private void MyPropertyCollection() {
    // Creates a new collection and assign it the properties for button1.
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
 
    // Displays each property in the collection in a text box.
    foreach (PropertyDescriptor myProperty in properties)
       textBox1.Text += myProperty.Name + '\n';
 }
private:
   void MyPropertyCollection()
   {
      // Creates a new collection and assign it the properties for button1.
      PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
      
      // Displays each property in the collection in a text box.
      for each ( PropertyDescriptor^ myProperty in properties )
      {
         textBox1->Text = String::Concat( textBox1->Text, myProperty->Name, "\n" );
      }
   }
private void MyPropertyCollection()
{
    // Creates a new collection and assign it the properties for button1.
    PropertyDescriptorCollection properties = 
        TypeDescriptor.GetProperties(button1);

    // Displays each property in the collection in a text box.
    for (int iCtr = 0; iCtr < properties.get_Count(); iCtr++) {
        PropertyDescriptor myProperty = properties.get_Item(iCtr);
        textBox1.set_Text(myProperty.get_Name() + '\n');
    }
} //MyPropertyCollection

Vererbungshierarchie

System.Object
  System.ComponentModel.PropertyDescriptorCollection

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

PropertyDescriptorCollection-Member
System.ComponentModel-Namespace
PropertyDescriptor-Klasse
TypeDescriptor