Share via


TypeDescriptor.GetProperties Metode

Definisi

Mengembalikan kumpulan properti pada komponen atau jenis.

Overload

GetProperties(Object, Attribute[], Boolean)

Mengembalikan kumpulan properti untuk komponen tertentu menggunakan array atribut tertentu sebagai filter dan menggunakan deskriptor jenis kustom.

GetProperties(Object, Boolean)

Mengembalikan kumpulan properti untuk komponen tertentu menggunakan pendeskripsi jenis default.

GetProperties(Type, Attribute[])

Mengembalikan kumpulan properti untuk jenis komponen tertentu menggunakan array atribut tertentu sebagai filter.

GetProperties(Type)

Mengembalikan kumpulan properti untuk jenis komponen tertentu.

GetProperties(Object)

Mengembalikan kumpulan properti untuk komponen tertentu.

GetProperties(Object, Attribute[])

Mengembalikan kumpulan properti untuk komponen tertentu menggunakan array atribut tertentu sebagai filter.

GetProperties(Object, Attribute[], Boolean)

Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs

Mengembalikan kumpulan properti untuk komponen tertentu menggunakan array atribut tertentu sebagai filter dan menggunakan deskriptor jenis kustom.

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

Parameter

component
Object

Komponen untuk mendapatkan properti.

attributes
Attribute[]

Array jenis Attribute untuk digunakan sebagai filter.

noCustomTypeDesc
Boolean

true untuk tidak mempertimbangkan informasi deskripsi jenis kustom; jika tidak, false.

Mengembalikan

PropertyDescriptorCollection dengan peristiwa yang cocok dengan atribut yang ditentukan untuk komponen yang ditentukan.

Pengecualian

component adalah objek jarak jauh lintas proses.

Keterangan

Properti untuk component bisa berbeda dari properti kelas, karena situs dapat menambahkan atau menghapus properti jika component situs.

Array attributes parameter digunakan untuk memfilter array. Pemfilteran ditentukan oleh aturan berikut:

  • Jika properti tidak memiliki Attribute kelas yang sama, properti tidak disertakan dalam array yang dikembalikan.

  • Jika atribut adalah instans Attribute kelas, properti harus sama persis atau tidak disertakan dalam array yang dikembalikan.

  • Attribute Jika instans ditentukan dan merupakan properti default, instans tersebut disertakan dalam array yang dikembalikan bahkan jika tidak ada instans Attribute di properti .

  • Jika attributes memiliki atribut default, GetProperties metode cocok dengan kasus ketika properti tidak memiliki atribut yang diterapkan.

component Jika parameter adalah null, koleksi kosong dikembalikan.

Urutan koleksi yang dikembalikan tidak dijamin identik di antara panggilan, jadi selalu pesan sebelum digunakan.

Lihat juga

Berlaku untuk

GetProperties(Object, Boolean)

Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs

Mengembalikan kumpulan properti untuk komponen tertentu menggunakan pendeskripsi jenis default.

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

Parameter

component
Object

Komponen untuk mendapatkan properti.

noCustomTypeDesc
Boolean

true untuk tidak mempertimbangkan informasi deskripsi jenis kustom; jika tidak, false.

Mengembalikan

PropertyDescriptorCollection dengan properti untuk komponen tertentu.

Pengecualian

component adalah objek jarak jauh lintas proses.

Keterangan

Properti untuk component parameter dapat berbeda dari properti kelas, karena situs dapat menambahkan atau menghapus properti jika component parameter di-site.

Jika component adalah null, koleksi kosong dikembalikan.

Urutan koleksi yang dikembalikan tidak dijamin identik di antara panggilan, jadi selalu pesan sebelum digunakan.

Lihat juga

Berlaku untuk

GetProperties(Type, Attribute[])

Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs

Mengembalikan kumpulan properti untuk jenis komponen tertentu menggunakan array atribut tertentu sebagai filter.

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

Parameter

componentType
Type

Komponen Type target.

attributes
Attribute[]

Array jenis Attribute untuk digunakan sebagai filter.

Mengembalikan

PropertyDescriptorCollection dengan properti yang cocok dengan atribut yang ditentukan untuk jenis komponen ini.

Contoh

Contoh kode berikut menunjukkan cara mengimplementasikan GetProperties metode . Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk PropertyTab kelas .

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

Keterangan

Panggil versi metode ini hanya ketika Anda tidak memiliki instans objek.

Array attributes parameter digunakan untuk memfilter array. Pemfilteran ditentukan oleh aturan berikut:

  • Jika properti tidak memiliki Attribute kelas yang sama, properti tidak disertakan dalam array yang dikembalikan.

  • Jika atribut adalah instans Attribute kelas, properti harus sama persis atau tidak disertakan dalam array yang dikembalikan.

  • Attribute Jika instans ditentukan dan merupakan properti default, instans tersebut disertakan dalam array yang dikembalikan bahkan jika tidak ada instans Attribute di properti .

  • Jika attributes memiliki atribut default, GetProperties metode cocok dengan kasus ketika properti tidak memiliki atribut yang diterapkan.

componentType Jika parameter adalah null, koleksi kosong dikembalikan.

Urutan koleksi yang dikembalikan tidak dijamin identik di antara panggilan, jadi selalu pesan sebelum digunakan.

Lihat juga

Berlaku untuk

GetProperties(Type)

Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs

Mengembalikan kumpulan properti untuk jenis komponen tertentu.

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

Parameter

componentType
Type

Type yang mewakili komponen untuk mendapatkan properti.

Mengembalikan

dengan PropertyDescriptorCollection properti untuk jenis komponen tertentu.

Keterangan

Panggil versi metode ini hanya ketika Anda tidak memiliki instans objek.

componentType Jika parameter adalah null, koleksi kosong dikembalikan.

Urutan koleksi yang dikembalikan tidak dijamin identik di antara panggilan, jadi selalu pesan sebelum digunakan.

Lihat juga

Berlaku untuk

GetProperties(Object)

Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs

Mengembalikan kumpulan properti untuk komponen tertentu.

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

Parameter

component
Object

Komponen untuk mendapatkan properti.

Mengembalikan

dengan PropertyDescriptorCollection properti untuk komponen yang ditentukan.

Pengecualian

component adalah objek jarak jauh lintas proses.

Contoh

Contoh kode berikut menunjukkan penggunaan GetProperties metode untuk mengakses properti kontrol. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ComponentDesigner kelas .

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

Keterangan

Properti untuk komponen dapat berbeda dari properti kelas, karena situs dapat menambahkan atau menghapus properti jika komponen di-site.

component Jika parameter adalah null, koleksi kosong dikembalikan.

Urutan koleksi yang dikembalikan tidak dijamin identik di antara panggilan, jadi selalu pesan sebelum digunakan.

Lihat juga

Berlaku untuk

GetProperties(Object, Attribute[])

Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs
Sumber:
TypeDescriptor.cs

Mengembalikan kumpulan properti untuk komponen tertentu menggunakan array atribut tertentu sebagai filter.

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

Parameter

component
Object

Komponen untuk mendapatkan properti.

attributes
Attribute[]

Array jenis Attribute untuk digunakan sebagai filter.

Mengembalikan

PropertyDescriptorCollection dengan properti yang cocok dengan atribut yang ditentukan untuk komponen yang ditentukan.

Pengecualian

component adalah objek jarak jauh lintas proses.

Contoh

Contoh kode berikut menunjukkan cara mengimplementasikan GetProperties metode . Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk PropertyTab kelas .

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

Keterangan

Properti untuk component parameter dapat berbeda dari properti kelas, karena situs dapat menambahkan atau menghapus properti jika component parameter di-site.

Array attributes parameter digunakan untuk memfilter array. Pemfilteran ditentukan oleh aturan berikut:

  • Jika properti tidak memiliki Attribute kelas yang sama, properti tidak disertakan dalam array yang dikembalikan.

  • Jika atribut adalah instans Attribute kelas, properti harus sama persis atau tidak disertakan dalam array yang dikembalikan.

  • Attribute Jika instans ditentukan dan merupakan properti default, instans tersebut disertakan dalam array yang dikembalikan bahkan jika tidak ada instans Attribute di properti .

  • Jika attributes memiliki atribut default, GetProperties metode cocok dengan kasus ketika properti tidak memiliki atribut yang diterapkan.

Jika component adalah null, koleksi kosong dikembalikan.

Urutan koleksi yang dikembalikan tidak dijamin identik di antara panggilan, jadi selalu pesan sebelum digunakan.

Lihat juga

Berlaku untuk