Specifies what type to use as a converter for the object this attribute is bound to. This class cannot be inherited.
For a list of all members of this type, see TypeConverterAttribute Members.
System.Object
System.Attribute
System.ComponentModel.TypeConverterAttribute
[Visual Basic] <AttributeUsage(AttributeTargets.All)> NotInheritable Public Class TypeConverterAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.All)] public sealed class TypeConverterAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::All)] public __gc __sealed class TypeConverterAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.All) class TypeConverterAttribute extends Attribute
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
The class you use for conversion must inherit from TypeConverter. Use the ConverterTypeName property to get the name of the class that provides the data conversion for the object this attribute is bound to.
For more information about attributes, see
[Visual Basic, C#] The following example tells MyClass to use the type converter called MyClassConverter. This example assumes that MyClassConverter has been implemented elsewhere. The class implementing the converter (MyClassConverter) must inherit from the TypeConverter class.
[Visual Basic] <TypeConverter(GetType(MyClassConverter))> _ Public Class ClassA ' Insert code here. End Class 'MyClass [C#] [TypeConverter(typeof(MyClassConverter))] public class MyClass { // Insert code here. }
[Visual Basic, C#] The next example creates an instance of MyClass. Then it gets the attributes for the class, and prints the name of the type converter used by MyClass.
[Visual Basic] Public Shared Function Main() As Integer ' Creates a new instance of ClassA. Dim myNewClass As New ClassA() ' Gets the attributes for the instance. Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewClass) ' Prints the name of the type converter by retrieving the ' TypeConverterAttribute from the AttributeCollection. Dim myAttribute As TypeConverterAttribute = _ CType(attributes(GetType(TypeConverterAttribute)), TypeConverterAttribute) Console.WriteLine(("The type conveter for this class is: " _ + myAttribute.ConverterTypeName)) Return 0 End Function 'Main [C#] public static int Main() { // Creates a new instance of MyClass. MyClass myNewClass = new MyClass(); // Gets the attributes for the instance. AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewClass); /* Prints the name of the type converter by retrieving the * TypeConverterAttribute from the AttributeCollection. */ TypeConverterAttribute myAttribute = (TypeConverterAttribute)attributes[typeof(TypeConverterAttribute)]; Console.WriteLine("The type conveter for this class is: " + myAttribute.ConverterTypeName); return 0; }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.ComponentModel
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
TypeConverterAttribute Members | System.ComponentModel Namespace | TypeConverter