Partager via


TypeDescriptor.GetProperties Méthode

Définition

Retourne la collection de propriétés sur un composant ou un type.

Surcharges

Nom Description
GetProperties(Object)

Retourne la collection de propriétés d’un composant spécifié.

GetProperties(Type)

Retourne la collection de propriétés d’un type de composant spécifié.

GetProperties(Object, Attribute[])

Retourne la collection de propriétés d’un composant spécifié à l’aide d’un tableau d’attributs spécifié en tant que filtre.

GetProperties(Object, Boolean)

Retourne la collection de propriétés d’un composant spécifié à l’aide du descripteur de type par défaut.

GetProperties(Type, Attribute[])

Retourne la collection de propriétés d’un type de composant spécifié à l’aide d’un tableau d’attributs spécifié en tant que filtre.

GetProperties(Object, Attribute[], Boolean)

Retourne la collection de propriétés d’un composant spécifié à l’aide d’un tableau d’attributs spécifié en tant que filtre et à l’aide d’un descripteur de type personnalisé.

GetProperties(Object)

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

Retourne la collection de propriétés d’un composant spécifié.

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

Paramètres

component
Object

Composant pour lequel obtenir les propriétés.

Retours

Avec PropertyDescriptorCollection les propriétés du composant spécifié.

Attributs

Exceptions

component est un objet distant interprocesseur.

Exemples

L’exemple de code suivant illustre l’utilisation de la GetProperties méthode pour accéder aux propriétés d’un contrôle. Cet exemple de code fait partie d’un exemple plus grand fourni pour la 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

Remarques

Les propriétés d’un composant peuvent différer des propriétés d’une classe, car le site peut ajouter ou supprimer des propriétés si le composant est sitené.

Si le component paramètre est null, une collection vide est retournée.

L’ordre de la collection retournée n’est pas garanti comme étant identique entre les appels. Il est donc toujours ordonné avant l’utilisation.

Voir aussi

S’applique à

GetProperties(Type)

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

Retourne la collection de propriétés d’un type de composant spécifié.

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

Paramètres

componentType
Type

Qui Type représente le composant pour lequel obtenir les propriétés.

Retours

Avec PropertyDescriptorCollection les propriétés d’un type de composant spécifié.

Attributs

Remarques

Appelez cette version de cette méthode uniquement lorsque vous n’avez pas d’instance de l’objet.

Si le componentType paramètre est null, une collection vide est retournée.

L’ordre de la collection retournée n’est pas garanti comme étant identique entre les appels. Il est donc toujours ordonné avant l’utilisation.

Voir aussi

S’applique à

GetProperties(Object, Attribute[])

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

Retourne la collection de propriétés d’un composant spécifié à l’aide d’un tableau d’attributs spécifié en tant que filtre.

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

Paramètres

component
Object

Composant pour lequel obtenir les propriétés.

attributes
Attribute[]

Tableau de type Attribute à utiliser comme filtre.

Retours

Avec PropertyDescriptorCollection les propriétés qui correspondent aux attributs spécifiés pour le composant spécifié.

Attributs

Exceptions

component est un objet distant interprocesseur.

Exemples

L’exemple de code suivant montre comment implémenter la GetProperties méthode. Cet exemple de code fait partie d’un exemple plus grand fourni pour la 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);

Remarques

Les propriétés du component paramètre peuvent différer des propriétés d’une classe, car le site peut ajouter ou supprimer des propriétés si le component paramètre est sitené.

Le tableau de attributes paramètres est utilisé pour filtrer le tableau. Le filtrage est défini par les règles suivantes :

  • Si une propriété n’a Attribute pas de même classe, la propriété n’est pas incluse dans le tableau retourné.

  • Si l’attribut est une instance de la Attribute classe, la propriété doit être une correspondance exacte ou elle n’est pas incluse dans le tableau retourné.

  • Si une Attribute instance est spécifiée et qu’elle est la propriété par défaut, elle est incluse dans le tableau retourné même s’il n’existe aucune instance de Attribute la propriété.

  • Si attributes elle a un attribut par défaut, la GetProperties méthode correspond au cas où la propriété n’a pas l’attribut appliqué.

Si component c’est nullle cas, une collection vide est retournée.

L’ordre de la collection retournée n’est pas garanti comme étant identique entre les appels. Il est donc toujours ordonné avant l’utilisation.

Voir aussi

S’applique à

GetProperties(Object, Boolean)

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

Retourne la collection de propriétés d’un composant spécifié à l’aide du descripteur de type par défaut.

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

Paramètres

component
Object

Composant pour lequel obtenir les propriétés.

noCustomTypeDesc
Boolean

true pour ne pas prendre en compte les informations de description de type personnalisées ; sinon, false.

Retours

Avec PropertyDescriptorCollection les propriétés d’un composant spécifié.

Attributs

Exceptions

component est un objet distant interprocesseur.

Remarques

Les propriétés du component paramètre peuvent différer des propriétés d’une classe, car le site peut ajouter ou supprimer des propriétés si le component paramètre est sitené.

Si component c’est nullle cas, une collection vide est retournée.

L’ordre de la collection retournée n’est pas garanti comme étant identique entre les appels. Il est donc toujours ordonné avant l’utilisation.

Voir aussi

S’applique à

GetProperties(Type, Attribute[])

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

Retourne la collection de propriétés d’un type de composant spécifié à l’aide d’un tableau d’attributs spécifié en tant que filtre.

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

Paramètres

componentType
Type

Composant Type cible.

attributes
Attribute[]

Tableau de type Attribute à utiliser comme filtre.

Retours

Avec PropertyDescriptorCollection les propriétés qui correspondent aux attributs spécifiés pour ce type de composant.

Attributs

Exemples

L’exemple de code suivant montre comment implémenter la GetProperties méthode. Cet exemple de code fait partie d’un exemple plus grand fourni pour la 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);

Remarques

Appelez cette version de cette méthode uniquement lorsque vous n’avez pas d’instance de l’objet.

Le tableau de attributes paramètres est utilisé pour filtrer le tableau. Le filtrage est défini par les règles suivantes :

  • Si une propriété n’a Attribute pas de même classe, la propriété n’est pas incluse dans le tableau retourné.

  • Si l’attribut est une instance de la Attribute classe, la propriété doit être une correspondance exacte ou elle n’est pas incluse dans le tableau retourné.

  • Si une Attribute instance est spécifiée et qu’elle est la propriété par défaut, elle est incluse dans le tableau retourné même s’il n’existe aucune instance de Attribute la propriété.

  • Si attributes elle a un attribut par défaut, la GetProperties méthode correspond au cas où la propriété n’a pas l’attribut appliqué.

Si le componentType paramètre est null, une collection vide est retournée.

L’ordre de la collection retournée n’est pas garanti comme étant identique entre les appels. Il est donc toujours ordonné avant l’utilisation.

Voir aussi

S’applique à

GetProperties(Object, Attribute[], Boolean)

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

Retourne la collection de propriétés d’un composant spécifié à l’aide d’un tableau d’attributs spécifié en tant que filtre et à l’aide d’un descripteur de type personnalisé.

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

Paramètres

component
Object

Composant pour lequel obtenir les propriétés.

attributes
Attribute[]

Tableau de type Attribute à utiliser comme filtre.

noCustomTypeDesc
Boolean

true pour ne pas prendre en compte les informations de description de type personnalisées ; sinon, false.

Retours

Avec PropertyDescriptorCollection les événements qui correspondent aux attributs spécifiés pour le composant spécifié.

Attributs

Exceptions

component est un objet distant interprocesseur.

Remarques

Les propriétés d’un objet component peuvent différer des propriétés d’une classe, car le site peut ajouter ou supprimer des propriétés si celui-ci component est sitené.

Le tableau de attributes paramètres est utilisé pour filtrer le tableau. Le filtrage est défini par les règles suivantes :

  • Si une propriété n’a Attribute pas de même classe, la propriété n’est pas incluse dans le tableau retourné.

  • Si l’attribut est une instance de la Attribute classe, la propriété doit être une correspondance exacte ou elle n’est pas incluse dans le tableau retourné.

  • Si une Attribute instance est spécifiée et qu’elle est la propriété par défaut, elle est incluse dans le tableau retourné même s’il n’existe aucune instance de Attribute la propriété.

  • Si attributes elle a un attribut par défaut, la GetProperties méthode correspond au cas où la propriété n’a pas l’attribut appliqué.

Si le component paramètre est null, une collection vide est retournée.

L’ordre de la collection retournée n’est pas garanti comme étant identique entre les appels. Il est donc toujours ordonné avant l’utilisation.

Voir aussi

S’applique à