TypeDescriptor 類別

定義

提供元件特性的相關資訊,例如其屬性 (attribute)、屬性 (property) 與事件。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. TypeDescriptor 可以透過目標群組件的 Site,以動態方式擴充數個可用的服務。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.

您可以透過兩種不同的方式來設定屬性和事件值:在 component 類別中指定它們,或在設計階段變更它們。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 和屬性 (Attribute) 陣列,從現有屬性 (Property) 描述項建立新屬性 (Property) 描述項。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)

傳回指定元件的屬性集合和布林值 (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)

使用指定的屬性 (Attribute) 陣列做為篩選條件,並使用自訂型別描述項,傳回指定元件的屬性 (Property) 集合。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[])

使用指定的屬性 (Attribute) 陣列做為篩選條件,傳回元件指定型別的屬性 (Property) 集合。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)

傳回可用來執行反映的 Type (已指定物件)。Returns a Type that can be used to perform reflection, given an object.

GetReflectionType(Type)

傳回可用來執行反映的 Type (已指定類別型別)。Returns 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()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

Refreshed

清除元件快取時發生。Occurs when the cache for a component is cleared.

適用於

另請參閱