TypeDescriptor.GetProperties 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳元件或型態上的屬性集合。
多載
| 名稱 | Description |
|---|---|
| GetProperties(Object) |
回傳指定元件的屬性集合。 |
| GetProperties(Type) |
回傳特定類型元件的屬性集合。 |
| GetProperties(Object, Attribute[]) |
回傳指定元件的屬性集合,並使用指定的屬性陣列作為過濾器。 |
| GetProperties(Object, Boolean) |
回傳指定元件的屬性集合,使用預設型別描述符。 |
| GetProperties(Type, Attribute[]) |
回傳特定類型元件的屬性集合,並使用指定的屬性陣列作為過濾器。 |
| GetProperties(Object, Attribute[], Boolean) |
回傳指定元件的屬性集合,使用指定的屬性陣列作為過濾器,並使用自訂型別描述符。 |
GetProperties(Object)
回傳指定元件的屬性集合。
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
一個用來取得屬性的元件。
傳回
PropertyDescriptorCollection A 具有指定元件的屬性。
- 屬性
例外狀況
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,則回傳一個空集合。
回傳集合的順序不保證每次呼叫都完全相同,因此使用前請務必先排序。
另請參閱
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
適用於
GetProperties(Type)
回傳特定類型元件的屬性集合。
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
參數
傳回
PropertyDescriptorCollection A 具有特定類型元件的屬性。
- 屬性
備註
只有在你沒有物件實例時才呼叫此方法版本。
若 componentType 參數為 null,則回傳一個空集合。
回傳集合的順序不保證每次呼叫都完全相同,因此使用前請務必先排序。
另請參閱
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
適用於
GetProperties(Object, Attribute[])
回傳指定元件的屬性集合,並使用指定的屬性陣列作為過濾器。
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
一個用來取得屬性的元件。
傳回
PropertyDescriptorCollection A 具有符合指定元件屬性的屬性。
- 屬性
例外狀況
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,則回傳一個空集合。
回傳集合的順序不保證每次呼叫都完全相同,因此使用前請務必先排序。
另請參閱
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
適用於
GetProperties(Object, Boolean)
回傳指定元件的屬性集合,使用預設型別描述符。
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
傳回
PropertyDescriptorCollection A 具有指定元件的屬性。
- 屬性
例外狀況
component 是一個跨程序的遠端物件。
備註
參數的 component 屬性可能與類別的性質不同,因為如果 component 參數被定位,網站可以新增或移除屬性。
若 component 是 null,則回傳一個空集合。
回傳集合的順序不保證每次呼叫都完全相同,因此使用前請務必先排序。
另請參閱
- PropertyDescriptor
- PropertyDescriptorCollection
- ICustomTypeDescriptor
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
適用於
GetProperties(Type, Attribute[])
回傳特定類型元件的屬性集合,並使用指定的屬性陣列作為過濾器。
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
參數
傳回
PropertyDescriptorCollection A 具有符合此類元件指定屬性的屬性。
- 屬性
範例
以下程式碼範例示範如何實作此 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,則回傳一個空集合。
回傳集合的順序不保證每次呼叫都完全相同,因此使用前請務必先排序。
另請參閱
- PropertyDescriptor
- PropertyDescriptorCollection
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents
適用於
GetProperties(Object, Attribute[], Boolean)
回傳指定元件的屬性集合,使用指定的屬性陣列作為過濾器,並使用自訂型別描述符。
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
一個用來取得屬性的元件。
- noCustomTypeDesc
- Boolean
true不考慮自訂型別描述資訊;否則,。 false
傳回
PropertyDescriptorCollection A 中包含符合指定屬性的事件。
- 屬性
例外狀況
component 是一個跨程序的遠端物件。
備註
a component 的屬性可能與類別的性質不同,因為若 被 component sited,該網站可以新增或移除屬性。
attributes參數陣列用於篩選陣列。 過濾定義如下規則:
若屬性沒有相同類別的 , Attribute 該屬性不會包含在回傳的陣列中。
若屬性是類別的 Attribute 實例,該屬性必須完全匹配,否則不包含在回傳的陣列中。
如果指定了一個 Attribute 實例且它是預設屬性,即使該屬性中沒有 的 Attribute 實例,該實例仍會包含在回傳陣列中。
如果
attributes有預設屬性, GetProperties 則該方法會與該屬性未套用該屬性的情況相符。
若 component 參數為 null,則回傳一個空集合。
回傳集合的順序不保證每次呼叫都完全相同,因此使用前請務必先排序。
另請參閱
- PropertyDescriptor
- PropertyDescriptorCollection
- ICustomTypeDescriptor
- GetProperties
- GetDefaultProperty
- CreateProperty
- GetAttributes
- GetEvents