PropertyDescriptorCollection 类

定义

表示 PropertyDescriptor 对象集合。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 IList
    interface IDictionary
    interface IEnumerable
Public Class PropertyDescriptorCollection
Implements IDictionary, IList
继承
PropertyDescriptorCollection
实现

示例

下面的代码示例使用上PropertyDescriptorCollection button1的属性创建一个新的。The following code example creates a new PropertyDescriptorCollection using the properties on button1. 它要求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. 它要求button1在窗textBox1体中实例化和。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

注解

PropertyDescriptorCollection是只读的;它不实现添加或移除属性的方法。PropertyDescriptorCollection is read-only; it does not implement methods that add or remove properties. 必须从此类继承以实现这些方法。You must inherit from this class to implement these methods.

使用PropertyDescriptorCollection类中可用的属性,可以查询集合中有关其内容的信息。Using the properties available in the PropertyDescriptorCollection class, you can query the collection about its contents. 使用 Count 属性可确定集合中的元素数。Use the Count property to determine the number of elements in the collection. Item[String]使用属性按索引号或按名称获取特定属性。Use the Item[String] property to get a specific property by index number or by name.

除了属性外,还可以使用Find方法从集合中获取具有指定名称的属性的说明。In addition to properties, you can use the Find method to get a description of the property with the specified name from the collection.

构造函数

PropertyDescriptorCollection(PropertyDescriptor[])

初始化 PropertyDescriptorCollection 类的新实例。Initializes a new instance of the PropertyDescriptorCollection class.

PropertyDescriptorCollection(PropertyDescriptor[], Boolean)

初始化 PropertyDescriptorCollection 类的新实例,该类可以是只读类。Initializes a new instance of the PropertyDescriptorCollection class, which is optionally read-only.

字段

Empty

指定一个可以使用的空集合,而不是创建一个不带任何项的新集合。Specifies an empty collection that you can use instead of creating a new one with no items. static 字段是只读的。This static field is read-only.

属性

Count

获取集合中属性说明符的数目。Gets the number of property descriptors in the collection.

Item[Int32]

获取或设置指定索引处的 PropertyDescriptorGets or sets the PropertyDescriptor at the specified index number.

Item[String]

获取或设置具有指定名称的 PropertyDescriptorGets or sets the PropertyDescriptor with the specified name.

方法

Add(PropertyDescriptor)

将指定的 PropertyDescriptor 添加到集合。Adds the specified PropertyDescriptor to the collection.

Clear()

从集合中删除所有 PropertyDescriptor 对象。Removes all PropertyDescriptor objects from the collection.

Contains(PropertyDescriptor)

返回集合是否包含给定的 PropertyDescriptorReturns 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.

(继承自 Object)
Find(String, Boolean)

返回具有指定名称的 PropertyDescriptor,使用布尔值指示是否忽略大小写。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.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IndexOf(PropertyDescriptor)

返回给定 PropertyDescriptor 的索引。Returns the index of the given PropertyDescriptor.

Insert(Int32, PropertyDescriptor)

PropertyDescriptor 添加到集合中指定的索引号位置。Adds the PropertyDescriptor to the collection at the specified index number.

InternalSort(IComparer)

使用指定的 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()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(PropertyDescriptor)

从集合中移除指定的 PropertyDescriptorRemoves the specified PropertyDescriptor from the collection.

RemoveAt(Int32)

从集合中移除指定索引位置的 PropertyDescriptorRemoves 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)

使用指定的 IComparer 对此集合中的成员排序。Sorts the members of this collection, 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.

Sort(String[], IComparer)

对此集合中的成员排序。Sorts the members of this collection. 首先应用指定的顺序,然后使用指定的 IComparer 进行排序。The specified order is applied first, followed by the sort using the specified IComparer.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

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)

IDictionary 中添加一个带有所提供的键和值的元素。Adds an element with the provided key and value to the IDictionary.

IDictionary.Clear()

IDictionary 中移除所有元素。Removes all elements from the IDictionary.

IDictionary.Contains(Object)

确定是否 IDictionary 包含带有指定键的元素。Determines whether the IDictionary contains an element with the specified key.

IDictionary.GetEnumerator()

返回该类的枚举数。Returns an enumerator for this class.

IDictionary.IsFixedSize

获取一个值,该值指示 IDictionary 是否具有固定大小。Gets a value indicating whether the IDictionary has a fixed size.

IDictionary.IsReadOnly

获取一个值,该值指示 IDictionary 是否为只读。Gets a value indicating whether the IDictionary is read-only.

IDictionary.Item[Object]

获取或设置具有指定键的元素。Gets or sets the element with the specified key.

IDictionary.Keys

获取包含 ICollection 的键的 IDictionaryGets an ICollection containing the keys of the IDictionary.

IDictionary.Remove(Object)

IDictionary 中移除包含指定键的元素。Removes the element with the specified key from the IDictionary.

IDictionary.Values

获取一个 ICollection,它包含 IDictionary 中的值。Gets an ICollection containing the values in the IDictionary.

IEnumerable.GetEnumerator()

返回 IEnumeratorIDictionaryReturns an IEnumerator for the IDictionary.

IList.Add(Object)

将某项添加到 IList 中。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.

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅