TypeDescriptor 类

定义

提供有关组件特征的信息,如组件的特性、属性和事件。Provides information about the characteristics for a component, such as its attributes, properties, and events. 此类不能被继承。This class cannot be inherited.

public ref class TypeDescriptor sealed
public sealed class TypeDescriptor
type TypeDescriptor = class
Public NotInheritable Class TypeDescriptor
继承
TypeDescriptor

注解

.NET Framework 提供了两种方法来访问类型的元数据: System.Reflection 命名空间中提供的反射 API 和 TypeDescriptor 类。The .NET Framework provides two ways to access metadata on a type: the reflection API provided in the System.Reflection namespace, and the TypeDescriptor class. 反射是适用于所有类型的常规机制,因为它的基础是在根 Object 类的 GetType 方法中建立的。Reflection is a general mechanism available to all types because its foundation is established in the GetType method of the root Object class. 它为类型返回的信息不是可扩展的,因为它不能在编译目标类型之后修改。The information it returns for a type is not extensible, in that it cannot be modified after compilation of the target type. 有关详细信息,请参阅反射中的主题。For more information, see the topics in Reflection.

与此相反,TypeDescriptor 是一种可扩展的组件检查机制:实现 IComponent 接口的类。In contrast, TypeDescriptor is an extensible inspection mechanism for components: those classes that implement the IComponent interface. 不同于反射,它不检查方法。Unlike reflection, it does not inspect for methods. 可以通过目标组件的 Site提供的多个服务对 TypeDescriptor 进行动态扩展。TypeDescriptor can be dynamically extended by several services available through the target component's Site. 下表显示了这些服务。The following table shows these services.

服务名称Service name 说明Description
IExtenderProvider 启用另一个类(如 ToolTip)来向组件提供额外的属性。Enables another class, such as ToolTip, to provide extra properties to a component.
ITypeDescriptorFilterService 允许其他对象修改组件公开的标准元数据。Enables another object to modify the standard metadata that is exposed by a component.
ICustomTypeDescriptor 使类能够完全并动态地指定其自己的元数据,从而替换 TypeDescriptor的标准检查机制。Enables a class to completely and dynamically specify its own metadata, replacing the standard inspection mechanism of TypeDescriptor.

TypeDescriptor 提供的扩展性使组件的设计时表示形式不同于它的实际运行时表示形式,这使得 TypeDescriptor 对于构建设计时基础结构很有用。The extensibility provided by TypeDescriptor allows the design-time representation of a component to differ from its actual run-time representation, which makes TypeDescriptor useful for building design-time infrastructure.

TypeDescriptor 中的所有方法都 staticAll the methods in TypeDescriptor are static. 不能创建此类的实例,也不能继承此类。You cannot create an instance of this class, and this class cannot be inherited.

您可以通过两种不同的方式来设置属性和事件值:在组件类中指定它们或在设计时更改它们。You can set property and event values two different ways: specify them in the component class or change them at design time. 由于可以通过两种方式设置这些值,因此 TypeDescriptor 的重载方法采用两种不同类型的参数:类类型或对象实例。Because you can set these values two ways, the overloaded methods of TypeDescriptor take two different types of parameters: a class type or an object instance.

如果要访问 TypeDescriptor 信息并且具有对象的实例,请使用调用组件的方法。When you want to access TypeDescriptor information and you have an instance of the object, use the method that calls for a component. 仅当没有对象的实例时,才使用调用类类型的方法。Use the method that calls for the class type only when you do not have an instance of the object.

属性和事件通过 TypeDescriptor 高速缓存。Properties and events are cached by TypeDescriptor for speed. 通常,它们在对象的生存期内保持不变。Typically, they are constant for the lifetime of an object. 但是,扩展程序提供程序和设计器可以更改对象的属性集。However, extender providers and designers can change the set of properties on an object. 如果是这种情况,则必须调用 Refresh 方法来更新缓存。If this is the case, then the Refresh method must be called to update the cache.

属性

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.

GetClassName(Object)

使用默认的类型说明符返回指定组件的类的名称。Returns the name of the class for the specified component using the default type descriptor.

GetClassName(Object, Boolean)

使用自定义类型说明符返回指定组件的类的名称。Returns the name of the class for the specified component using a custom type descriptor.

GetClassName(Type)

返回指定类型的类的名称。Returns the name of the class for the specified type.

GetComponentName(Object)

使用默认的类型说明符返回指定组件的名称。Returns the name of the specified component using the default type descriptor.

GetComponentName(Object, Boolean)

使用自定义类型说明符返回指定组件的名称。Returns the name of the specified component using a custom type descriptor.

GetConverter(Object)

返回指定组件类型的类型转换器。Returns a type converter for the type of the specified component.

GetConverter(Object, Boolean)

使用自定义类型说明符返回指定组件类型的类型转换器。Returns a type converter for the type of the specified component with a custom type descriptor.

GetConverter(Type)

返回指定类型的类型转换器。Returns a type converter for the specified type.

GetDefaultEvent(Object)

返回指定组件的默认事件。Returns the default event for the specified component.

GetDefaultEvent(Object, Boolean)

使用自定义类型说明符返回组件的默认事件。Returns the default event for a component with a custom type descriptor.

GetDefaultEvent(Type)

返回指定类型组件的默认事件。Returns the default event for the specified type of component.

GetDefaultProperty(Object)

返回指定组件的默认属性。Returns the default property for the specified component.

GetDefaultProperty(Object, Boolean)

使用自定义类型说明符返回指定组件的默认属性。Returns the default property for the specified component with a custom type descriptor.

GetDefaultProperty(Type)

返回指定类型组件的默认属性。Returns the default property for the specified type of component.

GetEditor(Object, Type)

用指定的基类型获取指定组件的编辑器。Gets an editor with the specified base type for the specified component.

GetEditor(Object, Type, Boolean)

使用指定的基类型和自定义类型说明符返回指定组件的编辑器。Returns an editor with the specified base type and with a custom type descriptor for the specified component.

GetEditor(Type, Type)

使用指定的基类型返回指定类型的编辑器。Returns an editor with the specified base type for the specified type.

GetEvents(Object)

返回指定组件的事件的集合。Returns the collection of events for the specified component.

GetEvents(Object, Attribute[])

通过将指定的特性数组用作筛选器,返回指定组件的事件的集合。Returns the collection of events for a specified component using a specified array of attributes as a filter.

GetEvents(Object, Attribute[], Boolean)

通过将指定的特性数组用作筛选器并使用自定义类型说明符,返回指定组件的事件的集合。Returns the collection of events for a specified component using a specified array of attributes as a filter and using a custom type descriptor.

GetEvents(Object, Boolean)

使用自定义类型说明符返回指定组件的事件的集合。Returns the collection of events for a specified component with a custom type descriptor.

GetEvents(Type)

返回指定类型组件的事件的集合。Returns the collection of events for a specified type of component.

GetEvents(Type, Attribute[])

通过将指定的特性数组用作筛选器,返回指定类型组件的事件的集合。Returns the collection of events for a specified type of component using a specified array of attributes as a filter.

GetFullComponentName(Object)

返回组件的完全限定名。Returns the fully qualified name of the component.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetProperties(Object)

返回指定组件的属性的集合。Returns the collection of properties for a specified component.

GetProperties(Object, Attribute[])

通过将指定的特性数组用作筛选器,返回指定组件的属性的集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter.

GetProperties(Object, Attribute[], Boolean)

通过将指定的特性数组用作筛选器并使用自定义类型说明符,返回指定组件的属性的集合。Returns the collection of properties for a specified component using a specified array of attributes as a filter and using a custom type descriptor.

GetProperties(Object, Boolean)

使用默认类型说明符来返回指定组件的属性的集合。Returns the collection of properties for a specified component using the default type descriptor.

GetProperties(Type)

返回指定类型组件的属性的集合。Returns the collection of properties for a specified type of component.

GetProperties(Type, Attribute[])

通过将指定的特性数组用作筛选器,返回指定类型组件的属性的集合。Returns the collection of properties for a specified type of component using a specified array of attributes as a filter.

GetProvider(Object)

返回指定组件的类型说明提供程序。Returns the type description provider for the specified component.

GetProvider(Type)

返回指定类型的类型说明提供程序。Returns the type description provider for the specified type.

GetReflectionType(Object)

如果给定对象,则返回可用于执行反射的 TypeReturns a Type that can be used to perform reflection, given an object.

GetReflectionType(Type)

如果给定类类型,则返回可用于执行反射的 TypeReturns a Type that can be used to perform reflection, given a class type.

GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
Refresh(Assembly)

从缓存中清除指定程序集的属性和事件。Clears the properties and events for the specified assembly from the cache.

Refresh(Module)

从缓存中清除指定模块的属性和事件。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()

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

(继承自 Object)

事件

Refreshed

清除了组件的缓存时发生。Occurs when the cache for a component is cleared.

适用于

另请参阅