TypeDescriptor.GetProperties 方法

定義

傳回元件或型別的屬性集合。Returns the collection of properties on a component or type.

多載

GetProperties(Object, Attribute[], Boolean)

使用指定的屬性 (Attribute) 陣列做為篩選條件,並使用自訂型別描述項,傳回指定元件的屬性 (Property) 集合。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[])

使用指定的屬性 (Attribute) 陣列做為篩選條件,傳回元件指定型別的屬性 (Property) 集合。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)

使用指定的屬性 (Attribute) 陣列做為篩選條件,並使用自訂型別描述項,傳回指定元件的屬性 (Property) 集合。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,其事件符合指定元件的指定屬性。A PropertyDescriptorCollection with the events that match the specified attributes for the specified component.

例外狀況

component 是跨處理序的遠端物件。component is a cross-process remoted object.

備註

component 的屬性可能與類別的屬性不同,因為如果 component 已放置,網站可以加入或移除屬性。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.

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 實例,而且它是預設屬性,即使屬性中沒有任何 Attribute 實例,它仍會包含在傳回的陣列中。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.

  • 如果 attributes 有預設屬性,則 GetProperties 方法會符合屬性未套用屬性的情況。If attributes has a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.

如果 null``component 參數,則會傳回空集合。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.

傳回

具有指定元件之屬性的 PropertyDescriptorCollectionA PropertyDescriptorCollection with the properties for a specified component.

例外狀況

component 是跨處理序的遠端物件。component is a cross-process remoted object.

備註

component 參數的屬性可能與類別的屬性不同,因為如果 component 參數已放置,網站可以加入或移除屬性。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.

如果 null``component,則會傳回空集合。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[])

使用指定的屬性 (Attribute) 陣列做為篩選條件,傳回元件指定型別的屬性 (Property) 集合。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,其屬性 (Property) 符合此類型元件的指定屬性 (Attribute)。A 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. 這個程式碼範例是針對 PropertyTab 類別所提供的較大範例的一部分。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 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 實例,而且它是預設屬性,即使屬性中沒有任何 Attribute 實例,它仍會包含在傳回的陣列中。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.

  • 如果 attributes 有預設屬性,則 GetProperties 方法會符合屬性未套用屬性的情況。If attributes has a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.

如果 null``componentType 參數,則會傳回空集合。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

表示要取得屬性之元件的 TypeA Type that represents the component to get properties for.

傳回

有指定元件類型屬性的 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.

如果 null``componentType 參數,則會傳回空集合。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.

傳回

具有指定元件之屬性的 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. 這個程式碼範例是針對 ComponentDesigner 類別所提供的較大範例的一部分。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
    {
        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.

如果 null``component 參數,則會傳回空集合。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,其屬性 (Property) 符合指定元件的指定屬性 (Attribute)。A 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. 這個程式碼範例是針對 PropertyTab 類別所提供的較大範例的一部分。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 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 參數的屬性可能與類別的屬性不同,因為如果 component 參數已放置,網站可以加入或移除屬性。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.

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 實例,而且它是預設屬性,即使屬性中沒有任何 Attribute 實例,它仍會包含在傳回的陣列中。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.

  • 如果 attributes 有預設屬性,則 GetProperties 方法會符合屬性未套用屬性的情況。If attributes has a default attribute, the GetProperties method matches the case when the property does not have the attribute applied.

如果 null``component,則會傳回空集合。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.

另請參閱

適用於