Compartilhar via


TypeDescriptor.GetProperties Método

Definição

Retorna a coleção de propriedades em um componente ou tipo.

Sobrecargas

Nome Description
GetProperties(Object)

Retorna a coleção de propriedades de um componente especificado.

GetProperties(Type)

Retorna a coleção de propriedades para um tipo de componente especificado.

GetProperties(Object, Attribute[])

Retorna a coleção de propriedades de um componente especificado usando uma matriz especificada de atributos como um filtro.

GetProperties(Object, Boolean)

Retorna a coleção de propriedades de um componente especificado usando o descritor de tipo padrão.

GetProperties(Type, Attribute[])

Retorna a coleção de propriedades de um tipo de componente especificado usando uma matriz de atributos especificada como um filtro.

GetProperties(Object, Attribute[], Boolean)

Retorna a coleção de propriedades de um componente especificado usando uma matriz especificada de atributos como um filtro e usando um descritor de tipo personalizado.

GetProperties(Object)

Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs

Retorna a coleção de propriedades de um componente especificado.

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

Parâmetros

component
Object

Um componente para o qual obter as propriedades.

Retornos

A PropertyDescriptorCollection com as propriedades do componente especificado.

Atributos

Exceções

component é um objeto remoto entre processos.

Exemplos

O exemplo de código a seguir demonstra o uso do GetProperties método para acessar as propriedades de um controle. Este exemplo de código faz parte de um exemplo maior fornecido para a ComponentDesigner classe.

// 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

Comentários

As propriedades de um componente podem ser diferentes das propriedades de uma classe, pois o site pode adicionar ou remover propriedades se o componente estiver no site.

Se o component parâmetro for null, uma coleção vazia será retornada.

A ordem da coleção retornada não tem a garantia de ser idêntica entre as chamadas, portanto, sempre solicite-a antes do uso.

Confira também

Aplica-se a

GetProperties(Type)

Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs

Retorna a coleção de propriedades para um tipo de componente especificado.

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

Parâmetros

componentType
Type

Um Type que representa o componente para o qual obter propriedades.

Retornos

A PropertyDescriptorCollection com as propriedades de um tipo de componente especificado.

Atributos

Comentários

Chame essa versão desse método somente quando você não tiver uma instância do objeto.

Se o componentType parâmetro for null, uma coleção vazia será retornada.

A ordem da coleção retornada não tem a garantia de ser idêntica entre as chamadas, portanto, sempre solicite-a antes do uso.

Confira também

Aplica-se a

GetProperties(Object, Attribute[])

Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs

Retorna a coleção de propriedades de um componente especificado usando uma matriz especificada de atributos como um filtro.

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

Parâmetros

component
Object

Um componente para o qual obter as propriedades.

attributes
Attribute[]

Uma matriz de tipo Attribute a ser usada como um filtro.

Retornos

Um PropertyDescriptorCollection com as propriedades que correspondem aos atributos especificados para o componente especificado.

Atributos

Exceções

component é um objeto remoto entre processos.

Exemplos

O exemplo de código a seguir demonstra como implementar o GetProperties método. Este exemplo de código faz parte de um exemplo maior fornecido para a PropertyTab classe.

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

Comentários

As propriedades do component parâmetro podem diferir das propriedades de uma classe, pois o site pode adicionar ou remover propriedades se o component parâmetro for site.

A attributes matriz de parâmetros é usada para filtrar a matriz. A filtragem é definida pelas seguintes regras:

  • Se uma propriedade não tiver uma Attribute da mesma classe, a propriedade não será incluída na matriz retornada.

  • Se o atributo for uma instância da Attribute classe, a propriedade deverá ser uma correspondência exata ou não está incluída na matriz retornada.

  • Se uma Attribute instância for especificada e for a propriedade padrão, ela será incluída na matriz retornada mesmo que não haja nenhuma instância da Attribute propriedade.

  • Se attributes tiver um atributo padrão, o GetProperties método corresponderá ao caso quando a propriedade não tiver o atributo aplicado.

Se component for null, uma coleção vazia será retornada.

A ordem da coleção retornada não tem a garantia de ser idêntica entre as chamadas, portanto, sempre solicite-a antes do uso.

Confira também

Aplica-se a

GetProperties(Object, Boolean)

Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs

Retorna a coleção de propriedades de um componente especificado usando o descritor de tipo padrão.

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

Parâmetros

component
Object

Um componente para o qual obter as propriedades.

noCustomTypeDesc
Boolean

true para não considerar informações de descrição de tipo personalizadas; caso contrário, false.

Retornos

A PropertyDescriptorCollection com as propriedades de um componente especificado.

Atributos

Exceções

component é um objeto remoto entre processos.

Comentários

As propriedades do component parâmetro podem diferir das propriedades de uma classe, pois o site pode adicionar ou remover propriedades se o component parâmetro for site.

Se component for null, uma coleção vazia será retornada.

A ordem da coleção retornada não tem a garantia de ser idêntica entre as chamadas, portanto, sempre solicite-a antes do uso.

Confira também

Aplica-se a

GetProperties(Type, Attribute[])

Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs

Retorna a coleção de propriedades de um tipo de componente especificado usando uma matriz de atributos especificada como um filtro.

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

Parâmetros

componentType
Type

O Type componente de destino.

attributes
Attribute[]

Uma matriz de tipo Attribute a ser usada como um filtro.

Retornos

Um PropertyDescriptorCollection com as propriedades que correspondem aos atributos especificados para esse tipo de componente.

Atributos

Exemplos

O exemplo de código a seguir demonstra como implementar o GetProperties método. Este exemplo de código faz parte de um exemplo maior fornecido para a PropertyTab classe.

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

Comentários

Chame essa versão desse método somente quando você não tiver uma instância do objeto.

A attributes matriz de parâmetros é usada para filtrar a matriz. A filtragem é definida pelas seguintes regras:

  • Se uma propriedade não tiver uma Attribute da mesma classe, a propriedade não será incluída na matriz retornada.

  • Se o atributo for uma instância da Attribute classe, a propriedade deverá ser uma correspondência exata ou não está incluída na matriz retornada.

  • Se uma Attribute instância for especificada e for a propriedade padrão, ela será incluída na matriz retornada mesmo que não haja nenhuma instância da Attribute propriedade.

  • Se attributes tiver um atributo padrão, o GetProperties método corresponderá ao caso quando a propriedade não tiver o atributo aplicado.

Se o componentType parâmetro for null, uma coleção vazia será retornada.

A ordem da coleção retornada não tem a garantia de ser idêntica entre as chamadas, portanto, sempre solicite-a antes do uso.

Confira também

Aplica-se a

GetProperties(Object, Attribute[], Boolean)

Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs
Origem:
TypeDescriptor.cs

Retorna a coleção de propriedades de um componente especificado usando uma matriz especificada de atributos como um filtro e usando um descritor de tipo personalizado.

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

Parâmetros

component
Object

Um componente para o qual obter as propriedades.

attributes
Attribute[]

Uma matriz de tipo Attribute a ser usada como um filtro.

noCustomTypeDesc
Boolean

true para não considerar informações de descrição de tipo personalizadas; caso contrário, false.

Retornos

Um PropertyDescriptorCollection com os eventos que correspondem aos atributos especificados para o componente especificado.

Atributos

Exceções

component é um objeto remoto entre processos.

Comentários

As propriedades de uma component classe podem diferir das propriedades de uma classe, pois o site pode adicionar ou remover propriedades se ela component estiver site.

A attributes matriz de parâmetros é usada para filtrar a matriz. A filtragem é definida pelas seguintes regras:

  • Se uma propriedade não tiver uma Attribute da mesma classe, a propriedade não será incluída na matriz retornada.

  • Se o atributo for uma instância da Attribute classe, a propriedade deverá ser uma correspondência exata ou não está incluída na matriz retornada.

  • Se uma Attribute instância for especificada e for a propriedade padrão, ela será incluída na matriz retornada mesmo que não haja nenhuma instância da Attribute propriedade.

  • Se attributes tiver um atributo padrão, o GetProperties método corresponderá ao caso quando a propriedade não tiver o atributo aplicado.

Se o component parâmetro for null, uma coleção vazia será retornada.

A ordem da coleção retornada não tem a garantia de ser idêntica entre as chamadas, portanto, sempre solicite-a antes do uso.

Confira também

Aplica-se a