Jason Bock

Home Biography Speaking Articles Books Music

TypeConverter Doesn’t Convert To Types

For some reason, the fact that the following code throws a NotSupportedException (‘TypeConverter’ is unable to convert ‘System.String’ to ‘System.Type’) made me laugh:

using System;
using System.ComponentModel;

namespace TypeConversion
{
  class Program
  {
    static void Main(string[] args)
    {
      TypeConverter converter = new TypeConverter();
      Type convertedType = (Type)converter.ConvertTo(
        "TypeConversion.Program, TypeConversion", typeof(Type));
    }
  }
}

Published: 03.26.2007 09:43:50 AM CST