Comparteix a través de


TypeDescriptor.GetProperties Método

Definición

Devuelve la colección de propiedades de un componente o tipo.

Sobrecargas

Nombre Description
GetProperties(Object)

Devuelve la colección de propiedades de un componente especificado.

GetProperties(Type)

Devuelve la colección de propiedades de un tipo de componente especificado.

GetProperties(Object, Attribute[])

Devuelve la colección de propiedades de un componente especificado mediante una matriz especificada de atributos como filtro.

GetProperties(Object, Boolean)

Devuelve la colección de propiedades de un componente especificado mediante el descriptor de tipo predeterminado.

GetProperties(Type, Attribute[])

Devuelve la colección de propiedades para un tipo de componente especificado utilizando una matriz especificada de atributos como filtro.

GetProperties(Object, Attribute[], Boolean)

Devuelve la colección de propiedades de un componente especificado mediante una matriz especificada de atributos como filtro y mediante un descriptor de tipo personalizado.

GetProperties(Object)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Devuelve la colección de propiedades de un 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

Componente para el que se obtienen las propiedades.

Devoluciones

con PropertyDescriptorCollection las propiedades del componente especificado.

Atributos

Excepciones

component es un objeto remoto entre procesos.

Ejemplos

En el ejemplo de código siguiente se muestra el uso del GetProperties método para acceder a las propiedades de un control. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la ComponentDesigner clase .

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

Comentarios

Las propiedades de un componente pueden diferir de las propiedades de una clase, ya que el sitio puede agregar o quitar propiedades si el componente está en el sitio.

Si el component parámetro es null, se devuelve una colección vacía.

No se garantiza que el orden de la colección devuelta sea idéntico entre las llamadas, por lo que siempre se ordena antes de su uso.

Consulte también

Se aplica a

GetProperties(Type)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Devuelve la colección de propiedades de un 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

Type que representa el componente para el que se van a obtener las propiedades.

Devoluciones

con PropertyDescriptorCollection las propiedades de un tipo de componente especificado.

Atributos

Comentarios

Llame a esta versión de este método solo cuando no tenga una instancia del objeto .

Si el componentType parámetro es null, se devuelve una colección vacía.

No se garantiza que el orden de la colección devuelta sea idéntico entre las llamadas, por lo que siempre se ordena antes de su uso.

Consulte también

Se aplica a

GetProperties(Object, Attribute[])

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Devuelve la colección de propiedades de un componente especificado mediante una matriz especificada de atributos como 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

Componente para el que se obtienen las propiedades.

attributes
Attribute[]

Matriz de tipo Attribute que se va a usar como filtro.

Devoluciones

con PropertyDescriptorCollection las propiedades que coinciden con los atributos especificados para el componente especificado.

Atributos

Excepciones

component es un objeto remoto entre procesos.

Ejemplos

En el ejemplo de código siguiente se muestra cómo implementar el GetProperties método . Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la PropertyTab clase .

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

Comentarios

Las propiedades del component parámetro pueden diferir de las propiedades de una clase, ya que el sitio puede agregar o quitar propiedades si el component parámetro está en el sitio.

La attributes matriz de parámetros se usa para filtrar la matriz. El filtrado se define mediante las siguientes reglas:

  • Si una propiedad no tiene una Attribute de la misma clase, la propiedad no se incluye en la matriz devuelta.

  • Si el atributo es una instancia de la Attribute clase , la propiedad debe ser una coincidencia exacta o no se incluye en la matriz devuelta.

  • Si se especifica una Attribute instancia y es la propiedad predeterminada, se incluye en la matriz devuelta incluso si no hay ninguna instancia de Attribute en la propiedad .

  • Si attributes tiene un atributo predeterminado, el GetProperties método coincide con el caso cuando la propiedad no tiene aplicado el atributo .

Si component es null, se devuelve una colección vacía.

No se garantiza que el orden de la colección devuelta sea idéntico entre las llamadas, por lo que siempre se ordena antes de su uso.

Consulte también

Se aplica a

GetProperties(Object, Boolean)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Devuelve la colección de propiedades de un componente especificado mediante el descriptor de tipo predeterminado.

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

Componente para el que se obtienen las propiedades.

noCustomTypeDesc
Boolean

true para no tener en cuenta la información de descripción del tipo personalizado; de lo contrario, false.

Devoluciones

con PropertyDescriptorCollection las propiedades de un componente especificado.

Atributos

Excepciones

component es un objeto remoto entre procesos.

Comentarios

Las propiedades del component parámetro pueden diferir de las propiedades de una clase, ya que el sitio puede agregar o quitar propiedades si el component parámetro está en el sitio.

Si component es null, se devuelve una colección vacía.

No se garantiza que el orden de la colección devuelta sea idéntico entre las llamadas, por lo que siempre se ordena antes de su uso.

Consulte también

Se aplica a

GetProperties(Type, Attribute[])

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Devuelve la colección de propiedades para un tipo de componente especificado utilizando una matriz especificada de atributos como 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

Type del componente de destino.

attributes
Attribute[]

Matriz de tipo Attribute que se va a usar como filtro.

Devoluciones

con PropertyDescriptorCollection las propiedades que coinciden con los atributos especificados para este tipo de componente.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo implementar el GetProperties método . Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la PropertyTab clase .

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

Comentarios

Llame a esta versión de este método solo cuando no tenga una instancia del objeto .

La attributes matriz de parámetros se usa para filtrar la matriz. El filtrado se define mediante las siguientes reglas:

  • Si una propiedad no tiene una Attribute de la misma clase, la propiedad no se incluye en la matriz devuelta.

  • Si el atributo es una instancia de la Attribute clase , la propiedad debe ser una coincidencia exacta o no se incluye en la matriz devuelta.

  • Si se especifica una Attribute instancia y es la propiedad predeterminada, se incluye en la matriz devuelta incluso si no hay ninguna instancia de Attribute en la propiedad .

  • Si attributes tiene un atributo predeterminado, el GetProperties método coincide con el caso cuando la propiedad no tiene aplicado el atributo .

Si el componentType parámetro es null, se devuelve una colección vacía.

No se garantiza que el orden de la colección devuelta sea idéntico entre las llamadas, por lo que siempre se ordena antes de su uso.

Consulte también

Se aplica a

GetProperties(Object, Attribute[], Boolean)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Devuelve la colección de propiedades de un componente especificado mediante una matriz especificada de atributos como filtro y mediante un descriptor 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

Componente para el que se obtienen las propiedades.

attributes
Attribute[]

Matriz de tipo Attribute que se va a usar como filtro.

noCustomTypeDesc
Boolean

true para no tener en cuenta la información de descripción del tipo personalizado; de lo contrario, false.

Devoluciones

con PropertyDescriptorCollection los eventos que coinciden con los atributos especificados para el componente especificado.

Atributos

Excepciones

component es un objeto remoto entre procesos.

Comentarios

Las propiedades de un component objeto pueden diferir de las propiedades de una clase, ya que el sitio puede agregar o quitar propiedades si está en el component sitio.

La attributes matriz de parámetros se usa para filtrar la matriz. El filtrado se define mediante las siguientes reglas:

  • Si una propiedad no tiene una Attribute de la misma clase, la propiedad no se incluye en la matriz devuelta.

  • Si el atributo es una instancia de la Attribute clase , la propiedad debe ser una coincidencia exacta o no se incluye en la matriz devuelta.

  • Si se especifica una Attribute instancia y es la propiedad predeterminada, se incluye en la matriz devuelta incluso si no hay ninguna instancia de Attribute en la propiedad .

  • Si attributes tiene un atributo predeterminado, el GetProperties método coincide con el caso cuando la propiedad no tiene aplicado el atributo .

Si el component parámetro es null, se devuelve una colección vacía.

No se garantiza que el orden de la colección devuelta sea idéntico entre las llamadas, por lo que siempre se ordena antes de su uso.

Consulte también

Se aplica a