TypeDescriptor.GetProperties Metodo

Definizione

Restituisce la raccolta di proprietà in un componente o un tipo.

Overload

GetProperties(Object, Attribute[], Boolean)

Restituisce la raccolta di proprietà per un componente specificato usando come filtro una matrice di attributi specificata e usando un descrittore di tipi personalizzato.

GetProperties(Object, Boolean)

Restituisce la raccolta di proprietà per un determinato componente usando il descrittore di tipo predefinito.

GetProperties(Type, Attribute[])

Restituisce la raccolta di proprietà per un tipo di componente specificato usando una matrice di attributi specificata come filtro.

GetProperties(Type)

Restituisce la raccolta di proprietà per un tipo di componente specificato.

GetProperties(Object)

Restituisce la raccolta di proprietà per un componente specificato.

GetProperties(Object, Attribute[])

Restituisce la raccolta di proprietà per un componente specificato usando una matrice di attributi specificata come filtro.

GetProperties(Object, Attribute[], Boolean)

Restituisce la raccolta di proprietà per un componente specificato usando come filtro una matrice di attributi specificata e usando un descrittore di tipi personalizzato.

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

Parametri

component
Object

Componente per il quale ottenere le proprietà.

attributes
Attribute[]

Matrice di tipo Attribute da usare come filtro.

noCustomTypeDesc
Boolean

true per non considerare le informazioni di descrizione dei tipi personalizzati; in caso contrario, false.

Restituisce

PropertyDescriptorCollection

Oggetto PropertyDescriptorCollection con gli eventi che corrispondono agli attributi specificati per il componente specificato.

Eccezioni

component è un oggetto remoto tra processi.

Commenti

Le proprietà di un component oggetto possono essere diverse dalle proprietà di una classe, perché il sito può aggiungere o rimuovere proprietà se il component sito è sito.

La attributes matrice di parametri viene usata per filtrare la matrice. Il filtro viene definito dalle regole seguenti:

  • Se una proprietà non ha una Attribute della stessa classe, la proprietà non è inclusa nella matrice restituita.

  • Se l'attributo è un'istanza della Attribute classe , la proprietà deve essere una corrispondenza esatta o non è inclusa nella matrice restituita.

  • Se viene specificata un'istanza Attribute di ed è la proprietà predefinita, viene inclusa nella matrice restituita anche se nella proprietà non è presente alcuna istanza di Attribute .

  • Se attributes ha un attributo predefinito, il GetProperties metodo corrisponde al caso in cui la proprietà non ha l'attributo applicato.

Se il component parametro è null, viene restituita una raccolta vuota.

L'ordine della raccolta restituita non è garantito che sia identico tra le chiamate, quindi ordinarlo sempre prima dell'uso.

Vedi anche

Si applica a

GetProperties(Object, Boolean)

Restituisce la raccolta di proprietà per un determinato componente usando il descrittore di tipo predefinito.

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

Parametri

component
Object

Componente per il quale ottenere le proprietà.

noCustomTypeDesc
Boolean

true per non considerare le informazioni di descrizione dei tipi personalizzati; in caso contrario, false.

Restituisce

PropertyDescriptorCollection

Oggetto PropertyDescriptorCollection con le proprietà per un componente specificato.

Eccezioni

component è un oggetto remoto tra processi.

Commenti

Le proprietà per il component parametro possono essere diverse dalle proprietà di una classe, perché il sito può aggiungere o rimuovere proprietà se il component parametro è in sito.

Se component è null, viene restituita una raccolta vuota.

L'ordine della raccolta restituita non è garantito essere identico tra le chiamate, quindi ordinarlo sempre prima dell'uso.

Vedi anche

Si applica a

GetProperties(Type, Attribute[])

Restituisce la raccolta di proprietà per un tipo di componente specificato usando una matrice di attributi specificata come filtro.

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

Parametri

componentType
Type

Oggetto Type del componente di destinazione.

attributes
Attribute[]

Matrice di tipo Attribute da usare come filtro.

Restituisce

PropertyDescriptorCollection

Oggetto PropertyDescriptorCollection con le proprietà che corrispondono agli attributi specificati per questo tipo di componente.

Esempio

Nell'esempio di codice seguente viene illustrato come implementare il GetProperties metodo. Questo esempio di codice fa parte di un esempio più grande fornito per 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 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

Commenti

Chiamare questa versione di questo metodo solo quando non si dispone di un'istanza dell'oggetto.

La attributes matrice di parametri viene usata per filtrare la matrice. Il filtro è definito dalle regole seguenti:

  • Se una proprietà non ha una Attribute della stessa classe, la proprietà non è inclusa nella matrice restituita.

  • Se l'attributo è un'istanza della Attribute classe, la proprietà deve essere una corrispondenza esatta o non è inclusa nella matrice restituita.

  • Se viene specificata un'istanza Attribute ed è la proprietà predefinita, è inclusa nella matrice restituita anche se non è presente alcuna istanza della Attribute proprietà.

  • Se attributes ha un attributo predefinito, il GetProperties metodo corrisponde al caso in cui la proprietà non ha l'attributo applicato.

Se il componentType parametro è null, viene restituita una raccolta vuota.

L'ordine della raccolta restituita non è garantito essere identico tra le chiamate, quindi ordinarlo sempre prima dell'uso.

Vedi anche

Si applica a

GetProperties(Type)

Restituisce la raccolta di proprietà per un tipo di componente specificato.

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

Parametri

componentType
Type

Oggetto Type che rappresenta il componente per il quale ottenere proprietà.

Restituisce

PropertyDescriptorCollection

Oggetto PropertyDescriptorCollection con le proprietà per un tipo di componente specificato.

Commenti

Chiamare questa versione di questo metodo solo quando non si dispone di un'istanza dell'oggetto.

Se il componentType parametro è null, viene restituita una raccolta vuota.

L'ordine della raccolta restituita non è garantito essere identico tra le chiamate, quindi ordinarlo sempre prima dell'uso.

Vedi anche

Si applica a

GetProperties(Object)

Restituisce la raccolta di proprietà per un componente specificato.

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

Parametri

component
Object

Componente per il quale ottenere le proprietà.

Restituisce

PropertyDescriptorCollection

Oggetto PropertyDescriptorCollection con le proprietà per un componente specificato.

Eccezioni

component è un oggetto remoto tra processi.

Esempio

Nell'esempio GetProperties di codice seguente viene illustrato l'uso del metodo per accedere alle proprietà di un controllo. Questo esempio di codice fa parte di un esempio più grande fornito per 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
    {
        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

Commenti

Le proprietà di un componente possono essere diverse dalle proprietà di una classe, perché il sito può aggiungere o rimuovere proprietà se il componente è in sito.

Se il component parametro è null, viene restituita una raccolta vuota.

L'ordine della raccolta restituita non è garantito essere identico tra le chiamate, quindi ordinarlo sempre prima dell'uso.

Vedi anche

Si applica a

GetProperties(Object, Attribute[])

Restituisce la raccolta di proprietà per un componente specificato usando una matrice di attributi specificata come filtro.

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

Parametri

component
Object

Componente per il quale ottenere le proprietà.

attributes
Attribute[]

Matrice di tipo Attribute da usare come filtro.

Restituisce

PropertyDescriptorCollection

Oggetto PropertyDescriptorCollection con le proprietà che corrispondono agli attributi specificati per il componente specificato.

Eccezioni

component è un oggetto remoto tra processi.

Esempio

Nell'esempio di codice seguente viene illustrato come implementare il GetProperties metodo. Questo esempio di codice fa parte di un esempio più grande fornito per 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 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

Commenti

Le proprietà per il component parametro possono essere diverse dalle proprietà di una classe, perché il sito può aggiungere o rimuovere proprietà se il component parametro è in sito.

La attributes matrice di parametri viene usata per filtrare la matrice. Il filtro è definito dalle regole seguenti:

  • Se una proprietà non ha una Attribute della stessa classe, la proprietà non è inclusa nella matrice restituita.

  • Se l'attributo è un'istanza della Attribute classe, la proprietà deve essere una corrispondenza esatta o non è inclusa nella matrice restituita.

  • Se viene specificata un'istanza Attribute ed è la proprietà predefinita, è inclusa nella matrice restituita anche se non è presente alcuna istanza della Attribute proprietà.

  • Se attributes ha un attributo predefinito, il GetProperties metodo corrisponde al caso in cui la proprietà non ha l'attributo applicato.

Se component è null, viene restituita una raccolta vuota.

L'ordine della raccolta restituita non è garantito essere identico tra le chiamate, quindi ordinarlo sempre prima dell'uso.

Vedi anche

Si applica a