Freigeben über


TypeDescriptor.GetProperties Methode

Definition

Gibt die Auflistung von Eigenschaften für eine Komponente oder einen Typ zurück.

Überlädt

Name Beschreibung
GetProperties(Object)

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente zurück.

GetProperties(Type)

Gibt die Auflistung von Eigenschaften für einen angegebenen Komponententyp zurück.

GetProperties(Object, Attribute[])

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente mithilfe eines angegebenen Arrays von Attributen als Filter zurück.

GetProperties(Object, Boolean)

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente mithilfe des Standardtypdeskriptors zurück.

GetProperties(Type, Attribute[])

Gibt die Auflistung von Eigenschaften für einen angegebenen Komponententyp zurück, wobei ein angegebenes Array von Attributen als Filter verwendet wird.

GetProperties(Object, Attribute[], Boolean)

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente zurück, die ein angegebenes Array von Attributen als Filter verwendet und einen benutzerdefinierten Typdeskriptor verwendet.

GetProperties(Object)

Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente zurück.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered.")]
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered.")>]
static member GetProperties : obj -> System.ComponentModel.PropertyDescriptorCollection
static member GetProperties : obj -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object) As PropertyDescriptorCollection

Parameter

component
Object

Eine Komponente, für die die Eigenschaften abgerufen werden sollen.

Gibt zurück

A PropertyDescriptorCollection mit den Eigenschaften für die angegebene Komponente.

Attribute

Ausnahmen

component ist ein prozessübergreifendes remoted-Objekt.

Beispiele

Das folgende Codebeispiel veranschaulicht die Verwendung der GetProperties Methode für den Zugriff auf die Eigenschaften eines Steuerelements. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die ComponentDesigner Klasse bereitgestellt wird.

// This is the shadowed property on the designer.
// This value will be serialized instead of the 
// value of the control's property.
public Color BackColor
{
    get => (Color)ShadowProperties[nameof(BackColor)];
    set
    {
        if (changeService != null)
        {
            PropertyDescriptor backColorDesc =
                TypeDescriptor.GetProperties(Control)["BackColor"];

            changeService.OnComponentChanging(
                Control,
                backColorDesc);

            ShadowProperties[nameof(BackColor)] = value;

            changeService.OnComponentChanged(
                Control,
                backColorDesc,
                null,
                null);
        }
    }
}
' This is the shadowed property on the designer.
' This value will be serialized instead of the 
' value of the control's property.

Public Property BackColor() As Color
    Get
        Return CType(ShadowProperties("BackColor"), Color)
    End Get
    Set(ByVal value As Color)
        If (Me.changeService IsNot Nothing) Then
            Dim backColorDesc As PropertyDescriptor = TypeDescriptor.GetProperties(Me.Control)("BackColor")

            Me.changeService.OnComponentChanging(Me.Control, backColorDesc)

            Me.ShadowProperties("BackColor") = value

            Me.changeService.OnComponentChanged(Me.Control, backColorDesc, Nothing, Nothing)
        End If
    End Set
End Property

Hinweise

Die Eigenschaften für eine Komponente können sich von den Eigenschaften einer Klasse unterscheiden, da die Website Eigenschaften hinzufügen oder entfernen kann, wenn die Komponente websited ist.

Wenn der component Parameter lautet null, wird eine leere Auflistung zurückgegeben.

Die Reihenfolge der zurückgegebenen Auflistung ist nicht garantiert identisch zwischen Aufrufen, sodass sie immer vor der Verwendung sortiert werden.

Weitere Informationen

Gilt für:

GetProperties(Type)

Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs

Gibt die Auflistung von Eigenschaften für einen angegebenen Komponententyp zurück.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(Type ^ componentType);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(Type componentType);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(Type componentType);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")>]
static member GetProperties : Type -> System.ComponentModel.PropertyDescriptorCollection
static member GetProperties : Type -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (componentType As Type) As PropertyDescriptorCollection

Parameter

componentType
Type

A Type that represents the component to get properties for.

Gibt zurück

A PropertyDescriptorCollection mit den Eigenschaften für einen angegebenen Komponententyp.

Attribute

Hinweise

Rufen Sie diese Version dieser Methode nur auf, wenn Sie keine Instanz des Objekts haben.

Wenn der componentType Parameter lautet null, wird eine leere Auflistung zurückgegeben.

Die Reihenfolge der zurückgegebenen Auflistung ist nicht garantiert identisch zwischen Aufrufen, sodass sie immer vor der Verwendung sortiert werden.

Weitere Informationen

Gilt für:

GetProperties(Object, Attribute[])

Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente mithilfe eines angegebenen Arrays von Attributen als Filter zurück.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component, cli::array <Attribute ^> ^ attributes);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, Attribute[]? attributes);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
static member GetProperties : obj * Attribute[] -> System.ComponentModel.PropertyDescriptorCollection
static member GetProperties : obj * Attribute[] -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object, attributes As Attribute()) As PropertyDescriptorCollection

Parameter

component
Object

Eine Komponente, für die die Eigenschaften abgerufen werden sollen.

attributes
Attribute[]

Ein Array vom Typ Attribute , das als Filter verwendet werden soll.

Gibt zurück

A PropertyDescriptorCollection mit den Eigenschaften, die den angegebenen Attributen für die angegebene Komponente entsprechen.

Attribute

Ausnahmen

component ist ein prozessübergreifendes remoted-Objekt.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die GetProperties Methode implementiert wird. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die PropertyTab Klasse bereitgestellt wird.

// Returns the properties of the specified component extended with
// a CategoryAttribute reflecting the name of the type of the property.
[ReflectionPermission(SecurityAction::Demand, Flags=ReflectionPermissionFlag::MemberAccess)]
virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component, array<System::Attribute^>^attributes ) override
{
   PropertyDescriptorCollection^ props;
   if ( attributes == nullptr )
            props = TypeDescriptor::GetProperties( component );
   else
            props = TypeDescriptor::GetProperties( component, attributes );

   array<PropertyDescriptor^>^propArray = gcnew array<PropertyDescriptor^>(props->Count);
   for ( int i = 0; i < props->Count; i++ )
   {
      // Create a new PropertyDescriptor from the old one, with
      // a CategoryAttribute matching the name of the type.
      array<Attribute^>^temp0 = {gcnew CategoryAttribute( props[ i ]->PropertyType->Name )};
      propArray[ i ] = TypeDescriptor::CreateProperty( props[ i ]->ComponentType, props[ i ], temp0 );

   }
   return gcnew PropertyDescriptorCollection( propArray );
}

virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component ) override
{
   return this->GetProperties( component, nullptr );
}
// Returns the properties of the specified component extended with 
// a CategoryAttribute reflecting the name of the type of the property.
public override PropertyDescriptorCollection GetProperties(object component, System.Attribute[] attributes)
{
    PropertyDescriptorCollection props = attributes == null ? TypeDescriptor.GetProperties(component) : TypeDescriptor.GetProperties(component, attributes);
    PropertyDescriptor[] propArray = new PropertyDescriptor[props.Count];
    for (int i = 0; i < props.Count; i++)
    {
        // Create a new PropertyDescriptor from the old one, with 
        // a CategoryAttribute matching the name of the type.
        propArray[i] = TypeDescriptor.CreateProperty(props[i].ComponentType, props[i], new CategoryAttribute(props[i].PropertyType.Name));
    }
    return new PropertyDescriptorCollection(propArray);
}

public override PropertyDescriptorCollection GetProperties(object component) => GetProperties(component, null);

Hinweise

Die Eigenschaften für den component Parameter können sich von den Eigenschaften einer Klasse unterscheiden, da die Website Eigenschaften hinzufügen oder entfernen kann, wenn der component Parameter websited ist.

Das attributes Parameterarray wird verwendet, um das Array zu filtern. Filterung wird durch die folgenden Regeln definiert:

  • Wenn eine Eigenschaft nicht über eine Attribute der gleichen Klasse verfügt, ist die Eigenschaft nicht im zurückgegebenen Array enthalten.

  • Wenn es sich bei dem Attribut um eine Instanz der Attribute Klasse handelt, muss die Eigenschaft eine genaue Übereinstimmung sein, oder sie ist nicht im zurückgegebenen Array enthalten.

  • Wenn eine Attribute Instanz angegeben ist und sie die Standardeigenschaft ist, wird sie in das zurückgegebene Array eingeschlossen, auch wenn keine Instanz der Attribute Eigenschaft vorhanden ist.

  • Wenn attributes ein Standard-Attribut vorhanden ist, entspricht die GetProperties Methode dem Fall, wenn die Eigenschaft nicht das Attribut angewendet hat.

Wenn component ja null, wird eine leere Auflistung zurückgegeben.

Die Reihenfolge der zurückgegebenen Auflistung ist nicht garantiert identisch zwischen Aufrufen, sodass sie immer vor der Verwendung sortiert werden.

Weitere Informationen

Gilt für:

GetProperties(Object, Boolean)

Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente mithilfe des Standardtypdeskriptors zurück.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component, bool noCustomTypeDesc);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered.")]
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, bool noCustomTypeDesc);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, bool noCustomTypeDesc);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered.")>]
static member GetProperties : obj * bool -> System.ComponentModel.PropertyDescriptorCollection
static member GetProperties : obj * bool -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object, noCustomTypeDesc As Boolean) As PropertyDescriptorCollection

Parameter

component
Object

Eine Komponente, für die die Eigenschaften abgerufen werden sollen.

noCustomTypeDesc
Boolean

truebenutzerdefinierte Typbeschreibungsinformationen nicht zu berücksichtigen; andernfalls . false

Gibt zurück

A PropertyDescriptorCollection mit den Eigenschaften für eine angegebene Komponente.

Attribute

Ausnahmen

component ist ein prozessübergreifendes remoted-Objekt.

Hinweise

Die Eigenschaften für den component Parameter können sich von den Eigenschaften einer Klasse unterscheiden, da die Website Eigenschaften hinzufügen oder entfernen kann, wenn der component Parameter websited ist.

Wenn component ja null, wird eine leere Auflistung zurückgegeben.

Die Reihenfolge der zurückgegebenen Auflistung ist nicht garantiert identisch zwischen Aufrufen, sodass sie immer vor der Verwendung sortiert werden.

Weitere Informationen

Gilt für:

GetProperties(Type, Attribute[])

Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs

Gibt die Auflistung von Eigenschaften für einen angegebenen Komponententyp zurück, wobei ein angegebenes Array von Attributen als Filter verwendet wird.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(Type ^ componentType, cli::array <Attribute ^> ^ attributes);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(Type componentType, Attribute[]? attributes);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(Type componentType, Attribute[] attributes);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
static member GetProperties : Type * Attribute[] -> System.ComponentModel.PropertyDescriptorCollection
static member GetProperties : Type * Attribute[] -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (componentType As Type, attributes As Attribute()) As PropertyDescriptorCollection

Parameter

componentType
Type

Die Type Zielkomponente.

attributes
Attribute[]

Ein Array vom Typ Attribute , das als Filter verwendet werden soll.

Gibt zurück

A PropertyDescriptorCollection mit den Eigenschaften, die den angegebenen Attributen für diesen Komponententyp entsprechen.

Attribute

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die GetProperties Methode implementiert wird. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die PropertyTab Klasse bereitgestellt wird.

// Returns the properties of the specified component extended with
// a CategoryAttribute reflecting the name of the type of the property.
[ReflectionPermission(SecurityAction::Demand, Flags=ReflectionPermissionFlag::MemberAccess)]
virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component, array<System::Attribute^>^attributes ) override
{
   PropertyDescriptorCollection^ props;
   if ( attributes == nullptr )
            props = TypeDescriptor::GetProperties( component );
   else
            props = TypeDescriptor::GetProperties( component, attributes );

   array<PropertyDescriptor^>^propArray = gcnew array<PropertyDescriptor^>(props->Count);
   for ( int i = 0; i < props->Count; i++ )
   {
      // Create a new PropertyDescriptor from the old one, with
      // a CategoryAttribute matching the name of the type.
      array<Attribute^>^temp0 = {gcnew CategoryAttribute( props[ i ]->PropertyType->Name )};
      propArray[ i ] = TypeDescriptor::CreateProperty( props[ i ]->ComponentType, props[ i ], temp0 );

   }
   return gcnew PropertyDescriptorCollection( propArray );
}

virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component ) override
{
   return this->GetProperties( component, nullptr );
}
// Returns the properties of the specified component extended with 
// a CategoryAttribute reflecting the name of the type of the property.
public override PropertyDescriptorCollection GetProperties(object component, System.Attribute[] attributes)
{
    PropertyDescriptorCollection props = attributes == null ? TypeDescriptor.GetProperties(component) : TypeDescriptor.GetProperties(component, attributes);
    PropertyDescriptor[] propArray = new PropertyDescriptor[props.Count];
    for (int i = 0; i < props.Count; i++)
    {
        // Create a new PropertyDescriptor from the old one, with 
        // a CategoryAttribute matching the name of the type.
        propArray[i] = TypeDescriptor.CreateProperty(props[i].ComponentType, props[i], new CategoryAttribute(props[i].PropertyType.Name));
    }
    return new PropertyDescriptorCollection(propArray);
}

public override PropertyDescriptorCollection GetProperties(object component) => GetProperties(component, null);

Hinweise

Rufen Sie diese Version dieser Methode nur auf, wenn Sie keine Instanz des Objekts haben.

Das attributes Parameterarray wird verwendet, um das Array zu filtern. Filterung wird durch die folgenden Regeln definiert:

  • Wenn eine Eigenschaft nicht über eine Attribute der gleichen Klasse verfügt, ist die Eigenschaft nicht im zurückgegebenen Array enthalten.

  • Wenn es sich bei dem Attribut um eine Instanz der Attribute Klasse handelt, muss die Eigenschaft eine genaue Übereinstimmung sein, oder sie ist nicht im zurückgegebenen Array enthalten.

  • Wenn eine Attribute Instanz angegeben ist und sie die Standardeigenschaft ist, wird sie in das zurückgegebene Array eingeschlossen, auch wenn keine Instanz der Attribute Eigenschaft vorhanden ist.

  • Wenn attributes ein Standard-Attribut vorhanden ist, entspricht die GetProperties Methode dem Fall, wenn die Eigenschaft nicht das Attribut angewendet hat.

Wenn der componentType Parameter lautet null, wird eine leere Auflistung zurückgegeben.

Die Reihenfolge der zurückgegebenen Auflistung ist nicht garantiert identisch zwischen Aufrufen, sodass sie immer vor der Verwendung sortiert werden.

Weitere Informationen

Gilt für:

GetProperties(Object, Attribute[], Boolean)

Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs
Quelle:
TypeDescriptor.cs

Gibt die Auflistung von Eigenschaften für eine angegebene Komponente zurück, die ein angegebenes Array von Attributen als Filter verwendet und einen benutzerdefinierten Typdeskriptor verwendet.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component, cli::array <Attribute ^> ^ attributes, bool noCustomTypeDesc);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, Attribute[]? attributes, bool noCustomTypeDesc);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes, bool noCustomTypeDesc);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")>]
static member GetProperties : obj * Attribute[] * bool -> System.ComponentModel.PropertyDescriptorCollection
static member GetProperties : obj * Attribute[] * bool -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object, attributes As Attribute(), noCustomTypeDesc As Boolean) As PropertyDescriptorCollection

Parameter

component
Object

Eine Komponente, für die die Eigenschaften abgerufen werden sollen.

attributes
Attribute[]

Ein Array vom Typ Attribute , das als Filter verwendet werden soll.

noCustomTypeDesc
Boolean

truebenutzerdefinierte Typbeschreibungsinformationen nicht zu berücksichtigen; andernfalls . false

Gibt zurück

A PropertyDescriptorCollection mit den Ereignissen, die den angegebenen Attributen für die angegebene Komponente entsprechen.

Attribute

Ausnahmen

component ist ein prozessübergreifendes remoted-Objekt.

Hinweise

Die Eigenschaften für eine component Klasse können sich von den Eigenschaften einer Klasse unterscheiden, da die Website Eigenschaften hinzufügen oder entfernen kann, wenn die component Website vorhanden ist.

Das attributes Parameterarray wird verwendet, um das Array zu filtern. Filterung wird durch die folgenden Regeln definiert:

  • Wenn eine Eigenschaft nicht über eine Attribute der gleichen Klasse verfügt, ist die Eigenschaft nicht im zurückgegebenen Array enthalten.

  • Wenn es sich bei dem Attribut um eine Instanz der Attribute Klasse handelt, muss die Eigenschaft eine genaue Übereinstimmung sein, oder sie ist nicht im zurückgegebenen Array enthalten.

  • Wenn eine Attribute Instanz angegeben ist und sie die Standardeigenschaft ist, wird sie in das zurückgegebene Array eingeschlossen, auch wenn keine Instanz der Attribute Eigenschaft vorhanden ist.

  • Wenn attributes ein Standard-Attribut vorhanden ist, entspricht die GetProperties Methode dem Fall, wenn die Eigenschaft nicht das Attribut angewendet hat.

Wenn der component Parameter lautet null, wird eine leere Auflistung zurückgegeben.

Die Reihenfolge der zurückgegebenen Auflistung ist nicht garantiert identisch zwischen Aufrufen, sodass sie immer vor der Verwendung sortiert werden.

Weitere Informationen

Gilt für: