Freigeben über


PropertyDescriptor-Klasse

Stellt eine Abstraktion einer Eigenschaft für eine Klasse bereit.

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public MustInherit Class PropertyDescriptor
    Inherits MemberDescriptor
'Usage
Dim instance As PropertyDescriptor
[ComVisibleAttribute(true)] 
public abstract class PropertyDescriptor : MemberDescriptor
[ComVisibleAttribute(true)] 
public ref class PropertyDescriptor abstract : public MemberDescriptor
/** @attribute ComVisibleAttribute(true) */ 
public abstract class PropertyDescriptor extends MemberDescriptor
ComVisibleAttribute(true) 
public abstract class PropertyDescriptor extends MemberDescriptor

Hinweise

Die Beschreibung einer Eigenschaft besteht aus einem Namen, den Attributen, der Komponentenklasse, der die Eigenschaft zugeordnet ist, und dem Eigenschaftentyp.

PropertyDescriptor stellt die folgenden Eigenschaften und Methoden bereit:

Die PropertyDescriptor-Klasse stellt außerdem die folgenden abstract-Eigenschaften und -Methoden bereit:

  • ComponentType enthält den Typ der Komponente, an die diese Eigenschaft gebunden ist.

  • IsReadOnly gibt an, ob diese Eigenschaft schreibgeschützt ist.

  • PropertyType ruft den Typ der Eigenschaft ab.

  • CanResetValue gibt an, ob durch das Zurücksetzen der Komponente ihr Wert geändert wird.

  • GetValue gibt den aktuellen Wert der Eigenschaft einer Komponente an.

  • ResetValue setzt den Wert der Komponente für diese Eigenschaft zurück.

  • SetValue legt den Wert der Komponente auf einen anderen Wert fest.

  • ShouldSerializeValue gibt an, ob der Wert dieser Eigenschaft beibehalten werden muss.

In der Regel werden die abstract-Member über Reflektion implementiert. Weitere Informationen über Reflektion finden Sie unter den Themen zu Reflektion.

Hinweis

Das auf diese Klasse angewendete HostProtectionAttribute-Attribut besitzt den Resources-Eigenschaftenwert SharedState. 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

Das folgende Codebeispiel basiert auf dem Beispiel in der PropertyDescriptorCollection-Klasse. Es gibt die Informationen (Kategorie, Beschreibung, Anzeigename) des Textes einer Schaltfläche in einem Textfeld aus. Dabei wird vorausgesetzt, dass button1 und textbox1 in einem Formular instanziiert wurden.

' 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
// 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';
// 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 = String::Concat( myProperty->DisplayName, "\n" );
textBox1->Text = String::Concat( textBox1->Text, myProperty->Description, "\n" );
textBox1->Text = String::Concat( textBox1->Text, myProperty->Category, "\n" );
// 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.set_Text(myProperty.get_DisplayName() + 'n');
textBox1.set_Text(textBox1.get_Text() + myProperty.get_Description() 
    + '\n');
textBox1.set_Text(textBox1.get_Text() + myProperty.get_Category()
    + '\n');

Vererbungshierarchie

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

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

PropertyDescriptor-Member
System.ComponentModel-Namespace
MemberDescriptor-Klasse
Attribute
DefaultValueAttribute-Klasse