TypeDescriptor.GetProperties Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the collection of properties on a component or type.
Overloads
| GetProperties(Object) |
Returns the collection of properties for a specified component. |
| GetProperties(Type) |
Returns the collection of properties for a specified type of component. |
| GetProperties(Object, Attribute[]) |
Returns the collection of properties for a specified component using a specified array of attributes as a filter. |
| 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(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)
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
Returns the collection of properties for a specified component.
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
Parameters
- component
- Object
A component to get the properties for.
Returns
A PropertyDescriptorCollection with the properties for the specified component.
- Attributes
Exceptions
component is a cross-process remoted object.
Examples
The following code example demonstrates the use of the GetProperties method to access the properties of a control. This 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 => (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
Remarks
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.
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.
See also
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
- How to: Access Design-time Services
Applies to
GetProperties(Type)
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
Returns the collection of properties for a specified type of component.
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
Parameters
Returns
A PropertyDescriptorCollection with the properties for a specified type of component.
- Attributes
Remarks
Call this version of this method only when you do not have an instance of the object.
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.
See also
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
Applies to
GetProperties(Object, Attribute[])
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
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);
[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
Parameters
- component
- Object
A component to get the properties for.
Returns
A PropertyDescriptorCollection with the properties that match the specified attributes for the specified component.
- Attributes
Exceptions
component is a cross-process remoted object.
Examples
The following code example demonstrates how to implement the GetProperties method. This 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 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);
Remarks
The 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.
The attributes parameter array is used to filter the array. Filtering is defined by the following rules:
If a property does not have an Attribute of the same class, the property is not included in the returned array.
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.
If 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.
If
attributeshas a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.
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.
See also
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
Applies to
GetProperties(Object, Boolean)
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
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);
[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
Parameters
- component
- Object
A component to get the properties for.
- noCustomTypeDesc
- Boolean
true to not consider custom type description information; otherwise, false.
Returns
A PropertyDescriptorCollection with the properties for a specified component.
- Attributes
Exceptions
component is a cross-process remoted object.
Remarks
The 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.
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.
See also
- PropertyDescriptor
- PropertyDescriptorCollection
- ICustomTypeDescriptor
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
Applies to
GetProperties(Type, Attribute[])
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
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);
[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
Parameters
Returns
A PropertyDescriptorCollection with the properties that match the specified attributes for this type of component.
- Attributes
Examples
The following code example demonstrates how to implement the GetProperties method. This 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 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);
Remarks
Call this version of this method only when you do not have an instance of the object.
The attributes parameter array is used to filter the array. Filtering is defined by the following rules:
If a property does not have an Attribute of the same class, the property is not included in the returned array.
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.
If 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.
If
attributeshas a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.
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.
See also
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
Applies to
GetProperties(Object, Attribute[], Boolean)
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
- Source:
- TypeDescriptor.cs
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);
[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
Parameters
- component
- Object
A component to get the properties for.
- noCustomTypeDesc
- Boolean
true to not consider custom type description information; otherwise, false.
Returns
A PropertyDescriptorCollection with the events that match the specified attributes for the specified component.
- Attributes
Exceptions
component is a cross-process remoted object.
Remarks
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.
The attributes parameter array is used to filter the array. Filtering is defined by the following rules:
If a property does not have an Attribute of the same class, the property is not included in the returned array.
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.
If 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.
If
attributeshas a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.
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.
See also
- PropertyDescriptor
- PropertyDescriptorCollection
- ICustomTypeDescriptor
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents