PropertyGrid使用总结3 Descriptor
Posted minhost
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PropertyGrid使用总结3 Descriptor相关的知识,希望对你有一定的参考价值。
Descriptor是实现当前对象描述的一个重要的类,其主要有以下几个类,这些类主要是进行。
1、TypeDescriptor
用于描述一个类型的信息,其是Type的一个扩充和补充,也可以用于类型转换等,这个类是一个最终类,无法继承此类。提供有关组件特征的信息,如组件的特性、属性和事件。
System.Reflection 命名空间中提供的反射 API 和 TypeDescriptor 类。 反射是适用于所有类型的常规机制,因为它的基础是在根 Object 类的 GetType 方法中建立的。 它为类型返回的信息不是可扩展的,因为它不能在编译目标类型之后修改。 有关详细信息,请参阅反射中的主题。
与此相反,TypeDescriptor 是一种可扩展的组件检查机制:实现 IComponent 接口的类。 不同于反射,它不检查方法。 可以通过目标组件的 Site提供的多个服务对 TypeDescriptor 进行动态扩展。
属性
ComNativeDescriptorHandler |
获取或设置用于目标组件的组件对象模型 (COM) 类型信息的提供程序。Gets or sets the provider for the Component Object Model (COM) type information for the target component. |
ComObjectType |
获取由目标组件表示的组件对象模型 (COM) 对象的类型。Gets the type of the Component Object Model (COM) object represented by the target component. |
InterfaceType |
获取一个类型,它表示所有接口类型的类型说明提供程序。Gets a type that represents a type description provider for all interface types. |
方法
AddAttributes(Object, Attribute[]) |
向目标组件实例添加类级别属性。Adds class-level attributes to the target component instance. |
AddAttributes(Type, Attribute[]) |
向目标组件类型添加类级别属性。Adds class-level attributes to the target component type. |
AddEditorTable(Type, Hashtable) |
为给定的编辑器基类型添加编辑器表。Adds an editor table for the given editor base type. |
AddProvider(TypeDescriptionProvider, Object) |
为某个组件的单个实例添加类型描述提供程序。Adds a type description provider for a single instance of a component. |
AddProvider(TypeDescriptionProvider, Type) |
为组件类添加类型说明提供程序。Adds a type description provider for a component class. |
AddProviderTransparent(TypeDescriptionProvider, Object) |
为某个组件的单个实例添加类型描述提供程序。Adds a type description provider for a single instance of a component. |
AddProviderTransparent(TypeDescriptionProvider, Type) |
为组件类添加类型说明提供程序。Adds a type description provider for a component class. |
CreateAssociation(Object, Object) |
在两个对象之间创建主要和辅助关联。Creates a primary-secondary association between two objects. |
CreateDesigner(IComponent, Type) |
创建与指定组件关联的具有特定类型的设计器的实例。Creates an instance of the designer associated with the specified component and of the specified type of designer. |
CreateEvent(Type, EventDescriptor, Attribute[]) |
当传递现有的 EventDescriptor 时,创建和现有事件描述符相同的新的事件描述符。Creates a new event descriptor that is identical to an existing event descriptor, when passed the existing EventDescriptor. |
CreateEvent(Type, String, Type, Attribute[]) |
通过从类型上的指定事件动态生成描述符信息,创建与现有事件描述符相同的新事件描述符。Creates a new event descriptor that is identical to an existing event descriptor by dynamically generating descriptor information from a specified event on a type. |
CreateInstance(IServiceProvider, Type, Type[], Object[]) |
创建可替换为另一种数据类型的对象。Creates an object that can substitute for another data type. |
CreateProperty(Type, PropertyDescriptor, Attribute[]) |
使用指定的现有 PropertyDescriptor 和特性数组,从现有的属性描述符创建一个新的属性描述符。Creates a new property descriptor from an existing property descriptor, using the specified existing PropertyDescriptor and attribute array. |
CreateProperty(Type, String, Type, Attribute[]) |
使用指定的属性名称、类型和属性数组创建属性描述符,并将其动态地绑定到类型。Creates and dynamically binds a property descriptor to a type, using the specified property name, type, and attribute array. |
Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
GetAssociation(Type, Object) |
返回与指定的主要对象关联的类型的实例。Returns an instance of the type associated with the specified primary object. |
GetAttributes(Object) |
返回指定组件的属性的集合。Returns the collection of attributes for the specified component. |
GetAttributes(Object, Boolean) |
为指定组件返回特性集合,并且创建了一个指示自定义类型描述符的布尔值。Returns a collection of attributes for the specified component and a Boolean indicating that a custom type descriptor has been created. |
GetAttributes(Type) |
返回指定组件类型的属性集合。Returns a collection of attributes for the specified type of component. |
使用默认类型描述符,返回指定组件的类的名称。Returns the name of the class for the specified component using the default type descriptor. |
|
使用自定义类型描述符返回指定组件的类的名称。Returns the name of the class for the specified component using a custom type descriptor. |
|
返回指定类型的类的名称。Returns the name of the class for the specified type. |
|
使用默认类型描述符返回指定组件的名称。Returns the name of the specified component using the default type descriptor. |
|
使用自定义类型描述符返回指定组件的名称。Returns the name of the specified component using a custom type descriptor. |
|
返回指定组件类型的类型转换器。Returns a type converter for the type of the specified component. |
|
为具有自定义类型描述符的指定组件类型返回一个类型转换器。Returns a type converter for the type of the specified component with a custom type descriptor. |
|
返回指定类型的类型转换器。Returns a type converter for the specified type. |
|
返回指定组件的默认事件。Returns the default event for the specified component. |
|
返回具有自定义类型描述符的组件的默认事件。Returns the default event for a component with a custom type descriptor. |
|
返回指定组件类型的默认事件。Returns the default event for the specified type of component. |
|
返回指定组件的默认属性。Returns the default property for the specified component. |
|
使用自定义类型描述符返回指定组件的默认属性。Returns the default property for the specified component with a custom type descriptor. |
|
返回指定类型组件的默认属性。Returns the default property for the specified type of component. |
|
获取指定组件的具有指定基类型的编辑器。Gets an editor with the specified base type for the specified component. |
|
为指定组件返回具有指定基类型和自定义类型描述符的编辑器。Returns an editor with the specified base type and with a custom type descriptor for the specified component. |
|
返回具有指定基类型的指定类型的编辑器。Returns an editor with the specified base type for the specified type. |
|
返回指定组件的事件的集合。Returns the collection of events for the specified component. |
|
通过将指定的属性数组用作筛选器来返回指定组件的事件集合。Returns the collection of events for a specified component using a specified array of attributes as a filter. |
|
通过使用指定的属性数组作为筛选器,并使用自定义类型描述符来返回指定组件的事件集合。Returns the collection of events for a specified component using a specified array of attributes as a filter and using a custom type descriptor. |
|
对具有自定义类型描述符的指定组件,返回事件集合。Returns the collection of events for a specified component with a custom type descriptor. |
|
返回指定组件类型的事件的集合。Returns the collection of events for a specified type of component. |
|
通过将指定的属性数组用作筛选器来返回指定组件类型的事件的集合。Returns the collection of events for a specified type of component using a specified array of attributes as a filter. |
|
返回组件的完全限定名。Returns the fully qualified name of the component. |
|
用作默认哈希函数。Serves as the default hash function. (继承自 Object) |
|
返回指定组件的属性的集合。Returns the collection of properties for a specified component. |
|
通过将指定的属性数组用作筛选器来返回指定组件的属性的集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter. |
|
通过使用指定的属性数组作为筛选器,并使用自定义类型描述符来返回指定组件的属性集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter and using a custom type descriptor. |
|
使用默认类型描述符为指定组件返回属性集合。Returns the collection of properties for a specified component using the default type descriptor. |
|
返回指定组件类型的属性的集合。Returns the collection of properties for a specified type of component. |
|
通过将指定的属性数组用作筛选器来为指定类型的组件返回属性的集合。Returns the collection of properties for a specified type of component using a specified array of attributes as a filter. |
|
返回指定组件的类型说明提供程序。Returns the type description provider for the specified component. |
|
返回指定类型的类型说明提供程序。Returns the type description provider for the specified type. |
|
如果给定对象,则返回可用于执行反射的 Type。Returns a Type that can be used to perform reflection, given an object. |
|
如果给定类类型,则返回可用于执行反射的 Type。Returns a Type that can be used to perform reflection, given a class type. |
|
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
|
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
|
从缓存中清除指定程序集的属性和事件。Clears the properties and events for the specified assembly from the cache. |
|
从缓存中清除指定模块的属性和事件。Clears the properties and events for the specified module from the cache. |
|
Refresh(Object) |
从缓存中清除指定组件的属性和事件。Clears the properties and events for the specified component from the cache. |
Refresh(Type) |
从缓存中清除指定类型的组件的属性和事件。Clears the properties and events for the specified type of component from the cache. |
RemoveAssociation(Object, Object) |
删除两个对象之间的关联。Removes an association between two objects. |
RemoveAssociations(Object) |
删除主要对象的所有关联。Removes all associations for a primary object. |
RemoveProvider(TypeDescriptionProvider, Object) |
移除以前添加的与指定对象关联的类型说明提供程序。Removes a previously added type description provider that is associated with the specified object. |
RemoveProvider(TypeDescriptionProvider, Type) |
删除以前添加的与指定类型关联的类型说明提供程序。Removes a previously added type description provider that is associated with the specified type. |
RemoveProviderTransparent(TypeDescriptionProvider, Object) |
移除以前添加的与指定对象关联的类型说明提供程序。Removes a previously added type description provider that is associated with the specified object. |
RemoveProviderTransparent(TypeDescriptionProvider, Type) |
删除以前添加的与指定类型关联的类型说明提供程序。Removes a previously added type description provider that is associated with the specified type. |
SortDescriptorArray(IList) |
使用描述符的名称对描述符排序。Sorts descriptors using the name of the descriptor. |
ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
事件
Refreshed |
清除了组件的缓存时发 |
EventDescriptorCollection events = TypeDescriptor.GetEvents(button1); foreach (System.ComponentModel.EventDescriptor myEvent in events) { textBox1.Text += myEvent.Category + ‘ ‘; textBox1.Text += myEvent.Description + ‘ ‘; textBox1.Text += myEvent.DisplayName + ‘ ‘; }
3、PropertyDescriptor
主要用于描述一个属性,主要用PropertyGrid进行属性的一些信息进行描述,其继承了父类MemberDescriptor。如下代码,可以获取所有属性的描述:
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1); System.ComponentModel.PropertyDescriptor myProperty = properties.Find("Text", false); textBox1.Text = myProperty.DisplayName+ ‘ ‘ ; textBox1.Text += myProperty.Description + ‘ ‘; textBox1.Text += myProperty.Category + ‘ ‘;
以上是关于PropertyGrid使用总结3 Descriptor的主要内容,如果未能解决你的问题,请参考以下文章