TypeDescriptor.GetProperties 方法

定义

返回组件或类型的属性的集合。Returns the collection of properties on a component or type.

重载

GetProperties(Object, Attribute[], Boolean)

通过使用指定的属性数组作为筛选器,并使用自定义类型描述符来返回指定组件的属性集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter and using a custom type descriptor.

GetProperties(Object, Boolean)

使用默认类型描述符为指定组件返回属性集合。Returns the collection of properties for a specified component using the default type descriptor.

GetProperties(Type, Attribute[])

通过将指定的属性数组用作筛选器来为指定类型的组件返回属性的集合。Returns the collection of properties for a specified type of component using a specified array of attributes as a filter.

GetProperties(Type)

返回指定组件类型的属性的集合。Returns the collection of properties for a specified type of component.

GetProperties(Object)

返回指定组件的属性的集合。Returns the collection of properties for a specified component.

GetProperties(Object, Attribute[])

通过将指定的属性数组用作筛选器来返回指定组件的属性的集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter.

GetProperties(Object, Attribute[], Boolean)

通过使用指定的属性数组作为筛选器,并使用自定义类型描述符来返回指定组件的属性集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter and using a custom type descriptor.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component, cli::array <Attribute ^> ^ attributes, bool noCustomTypeDesc);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties (object component, Attribute[] attributes, bool noCustomTypeDesc);
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

要为其获取属性的组件。A component to get the properties for.

attributes
Attribute[]

要用作筛选器的类型 Attribute 数组。An array of type Attribute to use as a filter.

noCustomTypeDesc
Boolean

如果为 true,则考虑自定义类型描述信息;否则为 falsetrue to consider custom type description information; otherwise, false.

返回

PropertyDescriptorCollection

具有与指定组件的指定属性相匹配的事件的 PropertyDescriptorCollectionA PropertyDescriptorCollection with the events that match the specified attributes for the specified component.

例外

component 是一个跨进程进行远程处理的对象。component is a cross-process remoted object.

注解

的属性 component 可能不同于类的属性,因为如果是,则站点可以添加或删除属性 componentThe properties for a component can differ from the properties of a class, because the site can add or remove properties if the component is sited.

attributes参数数组用于筛选数组。The attributes parameter array is used to filter the array. 筛选由以下规则定义:Filtering is defined by the following rules:

  • 如果某个属性不具有 Attribute 相同的类,则该属性不会包含在返回的数组中。If a property does not have an Attribute of the same class, the property is not included in the returned array.

  • 如果该属性是类的实例 Attribute ,则该属性必须是完全匹配项,否则它不会包含在返回的数组中。If the attribute is an instance of the Attribute class, the property must be an exact match or it is not included in the returned array.

  • 如果 Attribute 指定了实例并且它是默认属性,则即使属性中没有的实例,也会将其包含在返回的数组中 AttributeIf an Attribute instance is specified and it is the default property, it is included in the returned array even if there is no instance of the Attribute in the property.

  • 如果 attributes 具有默认属性,则 GetProperties 当属性没有应用特性时,方法会与大小写匹配。If attributes has a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.

如果 component 参数为 null ,则返回一个空集合。If the component parameter is null, an empty collection is returned.

返回的集合的顺序并不保证在两次调用之间是相同的,因此在使用之前始终对其进行排序。The order of the returned collection is not guaranteed to be identical between calls, so always order it before use.

另请参阅

适用于

GetProperties(Object, Boolean)

使用默认类型描述符为指定组件返回属性集合。Returns the collection of properties for a specified component using the default type descriptor.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component, bool noCustomTypeDesc);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties (object component, bool noCustomTypeDesc);
static member GetProperties : obj * bool -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object, noCustomTypeDesc As Boolean) As PropertyDescriptorCollection

参数

component
Object

要为其获取属性的组件。A component to get the properties for.

noCustomTypeDesc
Boolean

若不考虑自定义类型描述信息时,为 true;否则为 falsetrue to not consider custom type description information; otherwise, false.

返回

PropertyDescriptorCollection

具有指定组件的属性的 PropertyDescriptorCollectionA PropertyDescriptorCollection with the properties for a specified component.

例外

component 是一个跨进程进行远程处理的对象。component is a cross-process remoted object.

注解

参数的属性 component 可能不同于类的属性,因为如果该参数被放置,则站点可以添加或删除属性 componentThe properties for the component parameter can differ from the properties of a class, because the site can add or remove properties if the component parameter is sited.

如果 componentnull ,则返回一个空集合。If component is null, an empty collection is returned.

返回的集合的顺序并不保证在两次调用之间是相同的,因此在使用之前始终对其进行排序。The order of the returned collection is not guaranteed to be identical between calls, so always order it before use.

另请参阅

适用于

GetProperties(Type, Attribute[])

通过将指定的属性数组用作筛选器来为指定类型的组件返回属性的集合。Returns the collection of properties for a specified type of component using a specified array of attributes as a filter.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(Type ^ componentType, cli::array <Attribute ^> ^ attributes);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties (Type componentType, Attribute[] attributes);
static member GetProperties : Type * Attribute[] -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (componentType As Type, attributes As Attribute()) As PropertyDescriptorCollection

参数

componentType
Type

目标组件的 TypeThe Type of the target component.

attributes
Attribute[]

要用作筛选器的类型 Attribute 数组。An array of type Attribute to use as a filter.

返回

PropertyDescriptorCollection

具有与该类型组件的指定属性相匹配的属性的 PropertyDescriptorCollectionA PropertyDescriptorCollection with the properties that match the specified attributes for this type of component.

示例

下面的代码示例演示如何实现 GetProperties 方法。The following code example demonstrates how to implement the GetProperties method. 此代码示例是为类提供的更大示例的一部分 PropertyTabThis code example is part of a larger example provided for the PropertyTab class.

// 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 System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, System.Attribute[] attributes)
{
    PropertyDescriptorCollection props;
    if( attributes == null )
        props = TypeDescriptor.GetProperties(component);    
    else
        props = 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 System.ComponentModel.PropertyDescriptorCollection GetProperties(object component)
{                     
    return this.GetProperties(component, null);
}
' Returns the properties of the specified component extended with 
' a CategoryAttribute reflecting the name of the type of the property.
Public Overloads Overrides Function GetProperties(ByVal component As Object, ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection
    Dim props As PropertyDescriptorCollection
    If attributes Is Nothing Then
        props = TypeDescriptor.GetProperties(component)
    Else
        props = TypeDescriptor.GetProperties(component, attributes)
    End If
    Dim propArray(props.Count - 1) As PropertyDescriptor
    Dim i As Integer
    For i = 0 To props.Count - 1
        ' 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))
    Next i
    Return New PropertyDescriptorCollection(propArray)
End Function

Public Overloads Overrides Function GetProperties(ByVal component As Object) As System.ComponentModel.PropertyDescriptorCollection
    Return Me.GetProperties(component, Nothing)
End Function

注解

仅当没有对象的实例时,才调用此方法的此版本。Call this version of this method only when you do not have an instance of the object.

attributes参数数组用于筛选数组。The attributes parameter array is used to filter the array. 筛选由以下规则定义:Filtering is defined by the following rules:

  • 如果某个属性不具有 Attribute 相同的类,则该属性不会包含在返回的数组中。If a property does not have an Attribute of the same class, the property is not included in the returned array.

  • 如果该属性是类的实例 Attribute ,则该属性必须是完全匹配项,否则它不会包含在返回的数组中。If the attribute is an instance of the Attribute class, the property must be an exact match or it is not included in the returned array.

  • 如果 Attribute 指定了实例并且它是默认属性,则即使属性中没有的实例,也会将其包含在返回的数组中 AttributeIf an Attribute instance is specified and it is the default property, it is included in the returned array even if there is no instance of the Attribute in the property.

  • 如果 attributes 具有默认属性,则 GetProperties 当属性没有应用特性时,方法会与大小写匹配。If attributes has a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.

如果 componentType 参数为 null ,则返回一个空集合。If the componentType parameter is null, an empty collection is returned.

返回的集合的顺序并不保证在两次调用之间是相同的,因此在使用之前始终对其进行排序。The order of the returned collection is not guaranteed to be identical between calls, so always order it before use.

另请参阅

适用于

GetProperties(Type)

返回指定组件类型的属性的集合。Returns the collection of properties for a specified type of component.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(Type ^ componentType);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties (Type componentType);
static member GetProperties : Type -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (componentType As Type) As PropertyDescriptorCollection

参数

componentType
Type

一个 Type,表示要为其获取属性的组件。A Type that represents the component to get properties for.

返回

PropertyDescriptorCollection

具有指定组件类型的属性的 PropertyDescriptorCollectionA PropertyDescriptorCollection with the properties for a specified type of component.

注解

仅当没有对象的实例时,才调用此方法的此版本。Call this version of this method only when you do not have an instance of the object.

如果 componentType 参数为 null ,则返回一个空集合。If the componentType parameter is null, an empty collection is returned.

返回的集合的顺序并不保证在两次调用之间是相同的,因此在使用之前始终对其进行排序。The order of the returned collection is not guaranteed to be identical between calls, so always order it before use.

另请参阅

适用于

GetProperties(Object)

返回指定组件的属性的集合。Returns the collection of properties for a specified component.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties (object component);
static member GetProperties : obj -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object) As PropertyDescriptorCollection

参数

component
Object

要为其获取属性的组件。A component to get the properties for.

返回

PropertyDescriptorCollection

具有指定组件的属性的 PropertyDescriptorCollectionA PropertyDescriptorCollection with the properties for the specified component.

例外

component 是一个跨进程进行远程处理的对象。component is a cross-process remoted object.

示例

下面的代码示例演示如何使用 GetProperties 方法来访问控件的属性。The following code example demonstrates the use of the GetProperties method to access the properties of a control. 此代码示例是为类提供的更大示例的一部分 ComponentDesignerThis code example is part of a larger example provided for the ComponentDesigner class.

// 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
    {
        return (Color)ShadowProperties["BackColor"];
    }
    set
    {
        if (this.changeService != null)
        {
            PropertyDescriptor backColorDesc =
                TypeDescriptor.GetProperties(this.Control)["BackColor"];

            this.changeService.OnComponentChanging(
                this.Control,
                backColorDesc);

            this.ShadowProperties["BackColor"] = value;

            this.changeService.OnComponentChanged(
                this.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

注解

组件的属性可能不同于类的属性,因为如果组件已被放置,则站点可以添加或删除属性。The properties for a component can differ from the properties of a class, because the site can add or remove properties if the component is sited.

如果 component 参数为 null ,则返回一个空集合。If the component parameter is null, an empty collection is returned.

返回的集合的顺序并不保证在两次调用之间是相同的,因此在使用之前始终对其进行排序。The order of the returned collection is not guaranteed to be identical between calls, so always order it before use.

另请参阅

适用于

GetProperties(Object, Attribute[])

通过将指定的属性数组用作筛选器来返回指定组件的属性的集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component, cli::array <Attribute ^> ^ attributes);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties (object component, Attribute[] attributes);
static member GetProperties : obj * Attribute[] -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object, attributes As Attribute()) As PropertyDescriptorCollection

参数

component
Object

要为其获取属性的组件。A component to get the properties for.

attributes
Attribute[]

要用作筛选器的类型 Attribute 数组。An array of type Attribute to use as a filter.

返回

PropertyDescriptorCollection

具有与指定组件的指定属性相匹配的属性的 PropertyDescriptorCollectionA PropertyDescriptorCollection with the properties that match the specified attributes for the specified component.

例外

component 是一个跨进程进行远程处理的对象。component is a cross-process remoted object.

示例

下面的代码示例演示如何实现 GetProperties 方法。The following code example demonstrates how to implement the GetProperties method. 此代码示例是为类提供的更大示例的一部分 PropertyTabThis code example is part of a larger example provided for the PropertyTab class.

// 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 System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, System.Attribute[] attributes)
{
    PropertyDescriptorCollection props;
    if( attributes == null )
        props = TypeDescriptor.GetProperties(component);    
    else
        props = 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 System.ComponentModel.PropertyDescriptorCollection GetProperties(object component)
{                     
    return this.GetProperties(component, null);
}
' Returns the properties of the specified component extended with 
' a CategoryAttribute reflecting the name of the type of the property.
Public Overloads Overrides Function GetProperties(ByVal component As Object, ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection
    Dim props As PropertyDescriptorCollection
    If attributes Is Nothing Then
        props = TypeDescriptor.GetProperties(component)
    Else
        props = TypeDescriptor.GetProperties(component, attributes)
    End If
    Dim propArray(props.Count - 1) As PropertyDescriptor
    Dim i As Integer
    For i = 0 To props.Count - 1
        ' 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))
    Next i
    Return New PropertyDescriptorCollection(propArray)
End Function

Public Overloads Overrides Function GetProperties(ByVal component As Object) As System.ComponentModel.PropertyDescriptorCollection
    Return Me.GetProperties(component, Nothing)
End Function

注解

参数的属性 component 可能不同于类的属性,因为如果该参数被放置,则站点可以添加或删除属性 componentThe properties for the component parameter can differ from the properties of a class, because the site can add or remove properties if the component parameter is sited.

attributes参数数组用于筛选数组。The attributes parameter array is used to filter the array. 筛选由以下规则定义:Filtering is defined by the following rules:

  • 如果某个属性不具有 Attribute 相同的类,则该属性不会包含在返回的数组中。If a property does not have an Attribute of the same class, the property is not included in the returned array.

  • 如果该属性是类的实例 Attribute ,则该属性必须是完全匹配项,否则它不会包含在返回的数组中。If the attribute is an instance of the Attribute class, the property must be an exact match or it is not included in the returned array.

  • 如果 Attribute 指定了实例并且它是默认属性,则即使属性中没有的实例,也会将其包含在返回的数组中 AttributeIf an Attribute instance is specified and it is the default property, it is included in the returned array even if there is no instance of the Attribute in the property.

  • 如果 attributes 具有默认属性,则 GetProperties 当属性没有应用特性时,方法会与大小写匹配。If attributes has a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.

如果 componentnull ,则返回一个空集合。If component is null, an empty collection is returned.

返回的集合的顺序并不保证在两次调用之间是相同的,因此在使用之前始终对其进行排序。The order of the returned collection is not guaranteed to be identical between calls, so always order it before use.

另请参阅

适用于