TypeDescriptor.GetProperties Metod

Definition

Returnerar samlingen med egenskaper för en komponent eller typ.

Överlagringar

Name Description
GetProperties(Object, Attribute[], Boolean)

Returnerar samlingen med egenskaper för en angiven komponent med en angiven matris med attribut som ett filter och med hjälp av en anpassad typbeskrivning.

GetProperties(Object, Boolean)

Returnerar samlingen med egenskaper för en angiven komponent med standardtypbeskrivningen.

GetProperties(Type, Attribute[])

Returnerar samlingen med egenskaper för en angiven typ av komponent med en angiven matris med attribut som ett filter.

GetProperties(Type)

Returnerar samlingen med egenskaper för en angiven typ av komponent.

GetProperties(Object)

Returnerar samlingen med egenskaper för en angiven komponent.

GetProperties(Object, Attribute[])

Returnerar samlingen med egenskaper för en angiven komponent med en angiven matris med attribut som ett filter.

GetProperties(Object, Attribute[], Boolean)

Returnerar samlingen med egenskaper för en angiven komponent med en angiven matris med attribut som ett filter och med hjälp av en anpassad typbeskrivning.

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);
static member GetProperties : obj * Attribute[] * bool -> System.ComponentModel.PropertyDescriptorCollection
Public Shared Function GetProperties (component As Object, attributes As Attribute(), noCustomTypeDesc As Boolean) As PropertyDescriptorCollection

Parametrar

component
Object

En komponent att hämta egenskaperna för.

attributes
Attribute[]

En matris av typen Attribute som ska användas som ett filter.

noCustomTypeDesc
Boolean

trueför att inte ta hänsyn till information om beskrivning av anpassad typ. annars . false

Returer

A PropertyDescriptorCollection med de händelser som matchar de angivna attributen för den angivna komponenten.

Undantag

component är ett fjärrobjekt mellan processer.

Kommentarer

Egenskaperna för en component kan skilja sig från egenskaperna för en klass, eftersom webbplatsen kan lägga till eller ta bort egenskaper om den component är platsad.

Parametermatrisen attributes används för att filtrera matrisen. Filtrering definieras av följande regler:

  • Om en egenskap inte har en Attribute av samma klass inkluderas inte egenskapen i den returnerade matrisen.

  • Om attributet är en instans av Attribute klassen måste egenskapen vara en exakt matchning eller så ingår den inte i den returnerade matrisen.

  • Om en Attribute instans anges och det är standardegenskapen inkluderas den i den returnerade matrisen även om det inte finns någon instans av Attribute egenskapen i egenskapen.

  • Om attributes har ett standardattribut GetProperties matchar metoden fallet när egenskapen inte har attributet tillämpat.

Om parametern component är nullreturneras en tom samling.

Ordningen på den returnerade samlingen är inte garanterad att vara identisk mellan anrop, så beställ den alltid före användning.

Se även

Gäller för

GetProperties(Object, Boolean)

Returnerar samlingen med egenskaper för en angiven komponent med standardtypbeskrivningen.

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

Parametrar

component
Object

En komponent att hämta egenskaperna för.

noCustomTypeDesc
Boolean

trueför att inte ta hänsyn till information om beskrivning av anpassad typ. annars . false

Returer

A PropertyDescriptorCollection med egenskaperna för en angiven komponent.

Undantag

component är ett fjärrobjekt mellan processer.

Kommentarer

Egenskaperna för parametern component kan skilja sig från egenskaperna för en klass, eftersom platsen kan lägga till eller ta bort egenskaper om parametern component är platsad.

Om component är nullreturneras en tom samling.

Ordningen på den returnerade samlingen är inte garanterad att vara identisk mellan anrop, så beställ den alltid före användning.

Se även

Gäller för

GetProperties(Type, Attribute[])

Returnerar samlingen med egenskaper för en angiven typ av komponent med en angiven matris med attribut som ett filter.

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

Parametrar

componentType
Type

Målkomponentens Type .

attributes
Attribute[]

En matris av typen Attribute som ska användas som ett filter.

Returer

A PropertyDescriptorCollection med de egenskaper som matchar de angivna attributen för den här typen av komponent.

Exempel

Följande kodexempel visar hur du implementerar GetProperties metoden. Det här kodexemplet är en del av ett större exempel för PropertyTab klassen.

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

Kommentarer

Anropa endast den här versionen av den här metoden när du inte har någon instans av objektet.

Parametermatrisen attributes används för att filtrera matrisen. Filtrering definieras av följande regler:

  • Om en egenskap inte har en Attribute av samma klass inkluderas inte egenskapen i den returnerade matrisen.

  • Om attributet är en instans av Attribute klassen måste egenskapen vara en exakt matchning eller så ingår den inte i den returnerade matrisen.

  • Om en Attribute instans anges och det är standardegenskapen inkluderas den i den returnerade matrisen även om det inte finns någon instans av Attribute egenskapen i egenskapen.

  • Om attributes har ett standardattribut GetProperties matchar metoden fallet när egenskapen inte har attributet tillämpat.

Om parametern componentType är nullreturneras en tom samling.

Ordningen på den returnerade samlingen är inte garanterad att vara identisk mellan anrop, så beställ den alltid före användning.

Se även

Gäller för

GetProperties(Type)

Returnerar samlingen med egenskaper för en angiven typ av komponent.

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

Parametrar

componentType
Type

En Type som representerar komponenten som du vill hämta egenskaper för.

Returer

A PropertyDescriptorCollection med egenskaperna för en angiven typ av komponent.

Kommentarer

Anropa endast den här versionen av den här metoden när du inte har någon instans av objektet.

Om parametern componentType är nullreturneras en tom samling.

Ordningen på den returnerade samlingen är inte garanterad att vara identisk mellan anrop, så beställ den alltid före användning.

Se även

Gäller för

GetProperties(Object)

Returnerar samlingen med egenskaper för en angiven komponent.

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

Parametrar

component
Object

En komponent att hämta egenskaperna för.

Returer

A PropertyDescriptorCollection med egenskaperna för den angivna komponenten.

Undantag

component är ett fjärrobjekt mellan processer.

Exempel

I följande kodexempel visas hur metoden används GetProperties för att komma åt egenskaperna för en kontroll. Det här kodexemplet är en del av ett större exempel för ComponentDesigner klassen.

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

Kommentarer

Egenskaperna för en komponent kan skilja sig från egenskaperna för en klass, eftersom platsen kan lägga till eller ta bort egenskaper om komponenten är platsindelad.

Om parametern component är nullreturneras en tom samling.

Ordningen på den returnerade samlingen är inte garanterad att vara identisk mellan anrop, så beställ den alltid före användning.

Se även

Gäller för

GetProperties(Object, Attribute[])

Returnerar samlingen med egenskaper för en angiven komponent med en angiven matris med attribut som ett filter.

public:
 static System::ComponentModel::PropertyDescriptorCollection ^ GetProperties(System::Object ^ component, cli::array <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

Parametrar

component
Object

En komponent att hämta egenskaperna för.

attributes
Attribute[]

En matris av typen Attribute som ska användas som ett filter.

Returer

A PropertyDescriptorCollection med de egenskaper som matchar de angivna attributen för den angivna komponenten.

Undantag

component är ett fjärrobjekt mellan processer.

Exempel

Följande kodexempel visar hur du implementerar GetProperties metoden. Det här kodexemplet är en del av ett större exempel för PropertyTab klassen.

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

Kommentarer

Egenskaperna för parametern component kan skilja sig från egenskaperna för en klass, eftersom platsen kan lägga till eller ta bort egenskaper om parametern component är platsad.

Parametermatrisen attributes används för att filtrera matrisen. Filtrering definieras av följande regler:

  • Om en egenskap inte har en Attribute av samma klass inkluderas inte egenskapen i den returnerade matrisen.

  • Om attributet är en instans av Attribute klassen måste egenskapen vara en exakt matchning eller så ingår den inte i den returnerade matrisen.

  • Om en Attribute instans anges och det är standardegenskapen inkluderas den i den returnerade matrisen även om det inte finns någon instans av Attribute egenskapen i egenskapen.

  • Om attributes har ett standardattribut GetProperties matchar metoden fallet när egenskapen inte har attributet tillämpat.

Om component är nullreturneras en tom samling.

Ordningen på den returnerade samlingen är inte garanterad att vara identisk mellan anrop, så beställ den alltid före användning.

Se även

Gäller för