TypeDescriptor.GetProperties 方法

定義

傳回元件或類型之屬性的集合。

多載

GetProperties(Object, Attribute[], Boolean)

使用指定的屬性陣列做為篩選條件並使用自訂類型描述元,傳回指定元件的屬性集合。

GetProperties(Object, Boolean)

傳回使用預設類型描述元之指定元件的屬性集合。

GetProperties(Type, Attribute[])

使用指定的屬性陣列做為篩選條件,傳回元件指定類型的屬性集合。

GetProperties(Type)

傳回元件指定類型的屬性集合。

GetProperties(Object)

傳回指定元件的屬性集合。

GetProperties(Object, Attribute[])

使用指定的屬性陣列做為篩選條件,傳回指定元件的屬性集合。

GetProperties(Object, Attribute[], Boolean)

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

使用指定的屬性陣列做為篩選條件並使用自訂類型描述元,傳回指定元件的屬性集合。

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

要為其取得屬性的元件。

attributes
Attribute[]

做為篩選條件使用的 Attribute 類型陣列。

noCustomTypeDesc
Boolean

true 表示不考慮自訂類型描述資訊,否則為 false

傳回

PropertyDescriptorCollection,其事件符合指定元件的指定屬性。

例外狀況

component 是跨處理序的遠端物件。

備註

的屬性 component 可能會與類別的屬性不同,因為如果 已月臺,月臺可以新增或移除屬性 component

參數 attributes 陣列是用來篩選陣列。 篩選是由下列規則所定義:

  • 如果屬性沒有 Attribute 相同類別的 ,則屬性不會包含在傳回的陣列中。

  • 如果屬性是 類別的 Attribute 實例,則 屬性必須是完全相符的,或未包含在傳回的陣列中。

  • Attribute如果指定實例且它是預設屬性,則即使 屬性中沒有 的 Attribute 實例,它也會包含在傳回的陣列中。

  • 如果 attributes 具有預設屬性, GetProperties 則方法會比對屬性未套用屬性時的案例。

component如果 參數為 null ,則會傳回空的集合。

傳回集合的順序不保證在呼叫之間相同,因此一律先排序它再使用。

另請參閱

適用於

GetProperties(Object, Boolean)

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

傳回使用預設類型描述元之指定元件的屬性集合。

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

要為其取得屬性的元件。

noCustomTypeDesc
Boolean

true 表示不考慮自訂類型描述資訊,否則為 false

傳回

具有指定元件之屬性的 PropertyDescriptorCollection

例外狀況

component 是跨處理序的遠端物件。

備註

參數的屬性 component 可能與類別的屬性不同,因為如果參數已月臺,月臺可以新增或移除屬性 component

如果 為 componentnull ,則會傳回空集合。

傳回集合的順序不保證在呼叫之間相同,因此一律先排序它再使用。

另請參閱

適用於

GetProperties(Type, Attribute[])

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

使用指定的屬性陣列做為篩選條件,傳回元件指定類型的屬性集合。

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(Type ^ componentType, cli::array <Attribute ^> ^ attributes);
public static System.ComponentModel.PropertyDescriptorCollection GetProperties (Type componentType, 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

目標元件的 Type

attributes
Attribute[]

做為篩選條件使用的 Attribute 類型陣列。

傳回

PropertyDescriptorCollection,其屬性 (Property) 符合此類型元件的指定屬性 (Attribute)。

範例

下列程式碼範例示範如何實作 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 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);
}

備註

只有在您沒有 物件的實例時,才呼叫這個版本的這個方法。

參數 attributes 陣列是用來篩選陣列。 篩選是由下列規則所定義:

  • 如果屬性沒有 Attribute 相同類別的 ,則屬性不會包含在傳回的陣列中。

  • 如果屬性是 類別的 Attribute 實例,則 屬性必須是完全相符的,或未包含在傳回的陣列中。

  • Attribute如果指定實例且它是預設屬性,則即使 屬性中沒有 的 Attribute 實例,它也會包含在傳回的陣列中。

  • 如果 attributes 具有預設屬性, GetProperties 則方法會比對屬性未套用屬性時的案例。

componentType如果 參數為 null ,則會傳回空的集合。

傳回集合的順序不保證在呼叫之間相同,因此一律先排序它再使用。

另請參閱

適用於

GetProperties(Type)

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

傳回元件指定類型的屬性集合。

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

傳回

有指定元件類型屬性的 PropertyDescriptorCollection

備註

只有在您沒有 物件的實例時,才呼叫這個版本的這個方法。

componentType如果 參數為 null ,則會傳回空的集合。

傳回集合的順序不保證在呼叫之間相同,因此一律先排序它再使用。

另請參閱

適用於

GetProperties(Object)

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

傳回指定元件的屬性集合。

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

要為其取得屬性的元件。

傳回

具有指定元件之屬性的 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
    {
        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

備註

元件的屬性可能與類別的屬性不同,因為如果月臺已月臺,月臺可以新增或移除屬性。

component如果 參數為 null ,則會傳回空的集合。

傳回集合的順序不保證在呼叫之間相同,因此一律先排序它再使用。

另請參閱

適用於

GetProperties(Object, Attribute[])

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

使用指定的屬性陣列做為篩選條件,傳回指定元件的屬性集合。

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

要為其取得屬性的元件。

attributes
Attribute[]

做為篩選條件使用的 Attribute 類型陣列。

傳回

PropertyDescriptorCollection,其屬性 (Property) 符合指定元件的指定屬性 (Attribute)。

例外狀況

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

備註

參數的屬性 component 可能與類別的屬性不同,因為如果參數已月臺,月臺可以新增或移除屬性 component

參數 attributes 陣列是用來篩選陣列。 篩選是由下列規則所定義:

  • 如果屬性沒有 Attribute 相同類別的 ,則屬性不會包含在傳回的陣列中。

  • 如果屬性是 類別的 Attribute 實例,則 屬性必須是完全相符的,或未包含在傳回的陣列中。

  • Attribute如果指定實例且它是預設屬性,則即使 屬性中沒有 的 Attribute 實例,它也會包含在傳回的陣列中。

  • 如果 attributes 具有預設屬性, GetProperties 則方法會比對屬性未套用屬性時的案例。

如果 為 componentnull ,則會傳回空集合。

傳回集合的順序不保證在呼叫之間相同,因此一律先排序它再使用。

另請參閱

適用於