.NET Framework Class Library  

PropertyDescriptor Class

Provides an abstraction of a property on a class.

For a list of all members of this type, see PropertyDescriptor Members.

System.Object
   System.ComponentModel.MemberDescriptor
      System.ComponentModel.PropertyDescriptor
         System.ComponentModel.TypeConverter.SimplePropertyDescriptor

[Visual Basic]
<ComVisible(True)>
MustInherit Public Class PropertyDescriptor
   Inherits MemberDescriptor
[C#]
[ComVisible(true)]
public abstract class PropertyDescriptor : MemberDescriptor
[C++]
[ComVisible(true)]
public __gc __abstract class PropertyDescriptor : public
   MemberDescriptor
[JScript]
public
   ComVisible(true)
abstract class PropertyDescriptor extends MemberDescriptor

Thread Safety

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

Remarks

A description of a property consists of a name, its attributes, the component class that the property is associated with, and the type of the property.

PropertyDescriptor provides the following properties and methods:

PropertyDescriptor also provides the following abstract (MustOverride in Visual Basic) properties and methods:

Typically, the abstract (MustOverride in Visual Basic) members are implemented through reflection. For more information about reflection, see Discovering Type Information at Run Time.

Example

[Visual Basic, C#] The following example is built upon the example in the PropertyDescriptorCollection class. It prints the information (category, description, display name) of the Text of a button in a text box. It assumes that button1 and textbox1 have been instantiated on a form.

[Visual Basic] 
' Creates a new collection and assign it the properties for button1.
Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(Button1)

' Sets an PropertyDescriptor to the specific property.
Dim myProperty As PropertyDescriptor = properties.Find("Text", False)

' Prints the property and the property description.
TextBox1.Text += myProperty.DisplayName & Microsoft.VisualBasic.ControlChars.Cr
TextBox1.Text += myProperty.Description & Microsoft.VisualBasic.ControlChars.Cr
TextBox1.Text += myProperty.Category & Microsoft.VisualBasic.ControlChars.Cr

[C#] 
// Creates a new collection and assign it the properties for button1.
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);

// Sets an PropertyDescriptor to the specific property.
System.ComponentModel.PropertyDescriptor myProperty = properties.Find("Text", false);

// Prints the property and the property description.
textBox1.Text = myProperty.DisplayName+ '\n' ;
textBox1.Text += myProperty.Description + '\n';
textBox1.Text += myProperty.Category + '\n';

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET

Assembly: System (in System.dll)

See Also

PropertyDescriptor Members | System.ComponentModel Namespace | MemberDescriptor | Attribute | DefaultValueAttribute