Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

TypeDescriptor Class

Provides information about the characteristics for a component, such as its attributes, properties, and events. This class cannot be inherited.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)
[HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)]
public sealed class TypeDescriptor
NoteNote:

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

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. 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.

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 can be dynamically extended by several services available through the target component's Site. The following table shows these services.

Service name

Description

IExtenderProvider

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

Enables a class to completely and dynamically specify its own metadata, replacing the standard inspection mechanism of 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.

All 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. 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.

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.

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. If this is the case, then the Refresh method must be called to update the cache.

System.Object
  System.ComponentModel.TypeDescriptor
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.