TypeDescriptor.GetProperties 方法

定义

返回组件或类型的属性集合。

重载

名称 说明
GetProperties(Object)

返回指定组件的属性集合。

GetProperties(Type)

返回指定类型的组件的属性集合。

GetProperties(Object, Attribute[])

使用指定的属性数组作为筛选器返回指定组件的属性集合。

GetProperties(Object, Boolean)

使用默认类型描述符返回指定组件的属性集合。

GetProperties(Type, Attribute[])

返回使用指定属性数组作为筛选器的指定类型的组件的属性集合。

GetProperties(Object, Attribute[], Boolean)

使用指定的属性数组作为筛选器并使用自定义类型描述符返回指定组件的属性集合。

GetProperties(Object)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

返回指定组件的属性集合。

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

参数

component
Object

要获取其属性的组件。

返回

具有指定组件的属性的 A PropertyDescriptorCollection

属性

例外

component 是一个跨进程远程对象。

示例

下面的代码示例演示如何使用 GetProperties 该方法访问控件的属性。 该代码示例是 ComponentDesigner 类中的一个较大示例的一部分。

// 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

注解

组件的属性可能与类的属性不同,因为网站可以在站点中添加或删除属性(如果站点已站点)。

component如果参数为 null,则返回一个空集合。

不保证返回集合的顺序在调用之间相同,因此在使用之前始终按顺序排序。

另请参阅

适用于

GetProperties(Type)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

返回指定类型的组件的属性集合。

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

参数

componentType
Type

一个 Type 表示要为其获取属性的组件。

返回

具有指定类型的组件的属性的 A PropertyDescriptorCollection

属性

注解

仅当没有对象的实例时,才调用此方法的此版本。

componentType如果参数为 null,则返回一个空集合。

不保证返回集合的顺序在调用之间相同,因此在使用之前始终按顺序排序。

另请参阅

适用于

GetProperties(Object, Attribute[])

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

使用指定的属性数组作为筛选器返回指定组件的属性集合。

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

参数

component
Object

要获取其属性的组件。

attributes
Attribute[]

要用作筛选器的类型 Attribute 数组。

返回

具有与指定组件指定属性匹配的属性的 A PropertyDescriptorCollection

属性

例外

component 是一个跨进程远程对象。

示例

下面的代码示例演示如何实现该方法 GetProperties 。 该代码示例是 PropertyTab 类中的一个较大示例的一部分。

// 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);

注解

参数的属性 component 可能与类的属性不同,因为网站可以在网站中添加或删除属性(如果 component 参数已站点)。

参数 attributes 数组用于筛选数组。 筛选由以下规则定义:

  • 如果属性没有同一 Attribute 类,则返回的数组中不包含该属性。

  • 如果该属性是类的 Attribute 实例,则属性必须是完全匹配的,或者该属性不包含在返回的数组中。

  • 如果指定了实例 Attribute 并且它是默认属性,则即使该属性中没有实例 Attribute ,它也会包含在返回的数组中。

  • 如果 attributes 具有默认属性,则 GetProperties 当属性未应用该属性时,该方法将匹配该情况。

component如果是null,则返回一个空集合。

不保证返回集合的顺序在调用之间相同,因此在使用之前始终按顺序排序。

另请参阅

适用于

GetProperties(Object, Boolean)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

使用默认类型描述符返回指定组件的属性集合。

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

参数

component
Object

要获取其属性的组件。

noCustomTypeDesc
Boolean

true (不考虑自定义类型说明信息);否则,为 false.

返回

具有指定组件的属性的 A PropertyDescriptorCollection

属性

例外

component 是一个跨进程远程对象。

注解

参数的属性 component 可能与类的属性不同,因为网站可以在网站中添加或删除属性(如果 component 参数已站点)。

component如果是null,则返回一个空集合。

不保证返回集合的顺序在调用之间相同,因此在使用之前始终按顺序排序。

另请参阅

适用于

GetProperties(Type, Attribute[])

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

返回使用指定属性数组作为筛选器的指定类型的组件的属性集合。

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

参数

componentType
Type

Type目标组件。

attributes
Attribute[]

要用作筛选器的类型 Attribute 数组。

返回

PropertyDescriptorCollection 个属性,该属性与此类组件的指定属性匹配。

属性

示例

下面的代码示例演示如何实现该方法 GetProperties 。 该代码示例是 PropertyTab 类中的一个较大示例的一部分。

// 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);

注解

仅当没有对象的实例时,才调用此方法的此版本。

参数 attributes 数组用于筛选数组。 筛选由以下规则定义:

  • 如果属性没有同一 Attribute 类,则返回的数组中不包含该属性。

  • 如果该属性是类的 Attribute 实例,则属性必须是完全匹配的,或者该属性不包含在返回的数组中。

  • 如果指定了实例 Attribute 并且它是默认属性,则即使该属性中没有实例 Attribute ,它也会包含在返回的数组中。

  • 如果 attributes 具有默认属性,则 GetProperties 当属性未应用该属性时,该方法将匹配该情况。

componentType如果参数为 null,则返回一个空集合。

不保证返回集合的顺序在调用之间相同,因此在使用之前始终按顺序排序。

另请参阅

适用于

GetProperties(Object, Attribute[], Boolean)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

使用指定的属性数组作为筛选器并使用自定义类型描述符返回指定组件的属性集合。

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

参数

component
Object

要获取其属性的组件。

attributes
Attribute[]

要用作筛选器的类型 Attribute 数组。

noCustomTypeDesc
Boolean

true (不考虑自定义类型说明信息);否则,为 false.

返回

PropertyDescriptorCollection包含与指定组件指定属性匹配的事件。

属性

例外

component 是一个跨进程远程对象。

注解

component属性可能与类的属性不同,因为网站component可以在网站中添加或删除属性。

参数 attributes 数组用于筛选数组。 筛选由以下规则定义:

  • 如果属性没有同一 Attribute 类,则返回的数组中不包含该属性。

  • 如果该属性是类的 Attribute 实例,则属性必须是完全匹配的,或者该属性不包含在返回的数组中。

  • 如果指定了实例 Attribute 并且它是默认属性,则即使该属性中没有实例 Attribute ,它也会包含在返回的数组中。

  • 如果 attributes 具有默认属性,则 GetProperties 当属性未应用该属性时,该方法将匹配该情况。

component如果参数为 null,则返回一个空集合。

不保证返回集合的顺序在调用之间相同,因此在使用之前始终按顺序排序。

另请参阅

适用于