แก้ไข

แชร์ผ่าน


PropertyDescriptorCollection Class

Definition

Represents a collection of PropertyDescriptor objects.

public ref class PropertyDescriptorCollection : System::Collections::IDictionary, System::Collections::IList
public class PropertyDescriptorCollection : System.Collections.IDictionary, System.Collections.IList
type PropertyDescriptorCollection = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
    interface IList
type PropertyDescriptorCollection = class
    interface IList
    interface IDictionary
    interface ICollection
    interface IEnumerable
type PropertyDescriptorCollection = class
    interface ICollection
    interface IEnumerable
    interface IList
    interface IDictionary
Public Class PropertyDescriptorCollection
Implements IDictionary, IList
Inheritance
PropertyDescriptorCollection
Implements

Examples

The following code example creates a new PropertyDescriptorCollection using the properties on button1. It requires that button1 has been instantiated on a form.

PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)

The next example prints all the properties on a button in a text box. It requires that button1 and textBox1 have been instantiated on a form.

private:
   void MyPropertyCollection()
   {
      // Creates a new collection and assign it the properties for button1.
      PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
      
      // Displays each property in the collection in a text box.
      for each ( PropertyDescriptor^ myProperty in properties )
      {
         textBox1->Text = String::Concat( textBox1->Text, myProperty->Name, "\n" );
      }
   }
private void MyPropertyCollection() {
    // Creates a new collection and assign it the properties for button1.
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
 
    // Displays each property in the collection in a text box.
    foreach (PropertyDescriptor myProperty in properties)
       textBox1.Text += myProperty.Name + '\n';
 }
Private Sub MyPropertyCollection()
    ' Creates a new collection and assign it the properties for button1.
    Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
    
    ' Displays each property in the collection in a text box.
    Dim myProperty As PropertyDescriptor
    For Each myProperty In  properties
        textBox1.Text &= myProperty.Name & ControlChars.Cr
    Next myProperty
End Sub

Remarks

PropertyDescriptorCollection is read-only; it does not implement methods that add or remove properties. You must inherit from this class to implement these methods.

Using the properties available in the PropertyDescriptorCollection class, you can query the collection about its contents. Use the Count property to determine the number of elements in the collection. Use the Item[] property to get a specific property by index number or by name.

In addition to properties, you can use the Find method to get a description of the property with the specified name from the collection.

Constructors

PropertyDescriptorCollection(PropertyDescriptor[], Boolean)

Initializes a new instance of the PropertyDescriptorCollection class, which is optionally read-only.

PropertyDescriptorCollection(PropertyDescriptor[])

Initializes a new instance of the PropertyDescriptorCollection class.

Fields

Empty

Specifies an empty collection that you can use instead of creating a new one with no items. This static field is read-only.

Properties

Count

Gets the number of property descriptors in the collection.

Item[Int32]

Gets or sets the PropertyDescriptor at the specified index number.

Item[String]

Gets or sets the PropertyDescriptor with the specified name.

Methods

Add(PropertyDescriptor)

Adds the specified PropertyDescriptor to the collection.

Clear()

Removes all PropertyDescriptor objects from the collection.

Contains(PropertyDescriptor)

Returns whether the collection contains the given PropertyDescriptor.

CopyTo(Array, Int32)

Copies the entire collection to an array, starting at the specified index number.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Find(String, Boolean)

Returns the PropertyDescriptor with the specified name, using a Boolean to indicate whether to ignore case.

GetEnumerator()

Returns an enumerator for this class.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(PropertyDescriptor)

Returns the index of the given PropertyDescriptor.

Insert(Int32, PropertyDescriptor)

Adds the PropertyDescriptor to the collection at the specified index number.

InternalSort(IComparer)

Sorts the members of this collection, using the specified IComparer.

InternalSort(String[])

Sorts the members of this collection. The specified order is applied first, followed by the default sort for this collection, which is usually alphabetical.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(PropertyDescriptor)

Removes the specified PropertyDescriptor from the collection.

RemoveAt(Int32)

Removes the PropertyDescriptor at the specified index from the collection.

Sort()

Sorts the members of this collection, using the default sort for this collection, which is usually alphabetical.

Sort(IComparer)

Sorts the members of this collection, using the specified IComparer.

Sort(String[], IComparer)

Sorts the members of this collection. The specified order is applied first, followed by the sort using the specified IComparer.

Sort(String[])

Sorts the members of this collection. The specified order is applied first, followed by the default sort for this collection, which is usually alphabetical.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICollection.Count

Gets the number of elements contained in the collection.

ICollection.IsSynchronized

Gets a value indicating whether access to the collection is synchronized (thread safe).

ICollection.SyncRoot

Gets an object that can be used to synchronize access to the collection.

IDictionary.Add(Object, Object)

Adds an element with the provided key and value to the IDictionary.

IDictionary.Clear()

Removes all elements from the IDictionary.

IDictionary.Contains(Object)

Determines whether the IDictionary contains an element with the specified key.

IDictionary.GetEnumerator()

Returns an enumerator for this class.

IDictionary.IsFixedSize

Gets a value indicating whether the IDictionary has a fixed size.

IDictionary.IsReadOnly

Gets a value indicating whether the IDictionary is read-only.

IDictionary.Item[Object]

Gets or sets the element with the specified key.

IDictionary.Keys

Gets an ICollection containing the keys of the IDictionary.

IDictionary.Remove(Object)

Removes the element with the specified key from the IDictionary.

IDictionary.Values

Gets an ICollection containing the values in the IDictionary.

IEnumerable.GetEnumerator()

Returns an IEnumerator for the IDictionary.

IList.Add(Object)

Adds an item to the IList.

IList.Clear()

Removes all items from the collection.

IList.Contains(Object)

Determines whether the collection contains a specific value.

IList.IndexOf(Object)

Determines the index of a specified item in the collection.

IList.Insert(Int32, Object)

Inserts an item into the collection at a specified index.

IList.IsFixedSize

Gets a value indicating whether the collection has a fixed size.

IList.IsReadOnly

Gets a value indicating whether the collection is read-only.

IList.Item[Int32]

Gets or sets an item from the collection at a specified index.

IList.Remove(Object)

Removes the first occurrence of a specified value from the collection.

IList.RemoveAt(Int32)

Removes the item at the specified index.

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also