Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TypeConverterAttribute Class

Specifies what type to use as a converter for the object this attribute is bound to. This class cannot be inherited.

Namespace: System.ComponentModel
Assembly: System (in system.dll)

[AttributeUsageAttribute(AttributeTargets.All)] 
public sealed class TypeConverterAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All) */ 
public final class TypeConverterAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All) 
public final class TypeConverterAttribute extends Attribute
Not applicable.

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 Attributes Overview and Extending Metadata Using Attributes. For more information about type converters, see the TypeConverter base class and How to: Implement a Type Converter.

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.

[TypeConverter(typeof(MyClassConverter))]
 public class MyClass {
    // Insert code here.
 }

/** @attribute TypeConverter(MyClassConverter.class)
 */
public static class MyClass
{
    // Insert code here.
} //MyClass   

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.

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;
 }

public static void main(String[] args)
{
    // 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.get_Item( TypeConverterAttribute.class.ToType())));
    Console.WriteLine(("The type conveter for this class is: " 
        + myAttribute.get_ConverterTypeName()));
   } //main 

System.Object
   System.Attribute
    System.ComponentModel.TypeConverterAttribute

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

Show:
© 2014 Microsoft