Export (0) Print
Expand All

PropertyDescriptorCollection Class

Represents a collection of PropertyDescriptor objects.

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

public class PropertyDescriptorCollection : IList, IDictionary, ICollection, 
	IEnumerable
public class PropertyDescriptorCollection implements IList, IDictionary, 
	ICollection, IEnumerable
public class PropertyDescriptorCollection implements IList, IDictionary, 
	ICollection, IEnumerable
Not applicable.

PropertyDescriptorCollection is read-only; it does not implement methods that add or remove properties. You must inherit from this class to implement these methods.

Using the properties available in the PropertyDescriptorCollection class, you can query the collection about its contents. Use the Count property to determine the number of elements in the collection. Use the Item property to get a specific property by index number or by name.

In addition to properties, you can use the Find method to get a description of the property with the specified name from the collection.

NoteNote:

The HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following code example creates a new PropertyDescriptorCollection using the properties on button1. It requires that button1 has been instantiated on a form.

PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);

PropertyDescriptorCollection properties = 
    TypeDescriptor.GetProperties(button1);

The next example prints all the properties on a button in a text box. It requires that button1 and textBox1 have been instantiated on a form.

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 (int iCtr = 0; iCtr < properties.get_Count(); iCtr++) {
        PropertyDescriptor myProperty = properties.get_Item(iCtr);
        textBox1.set_Text(myProperty.get_Name() + '\n');
    }
} //MyPropertyCollection

System.Object
  System.ComponentModel.PropertyDescriptorCollection

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft