TypeDescriptor.GetConverter(typeof(string)).ConvertTo(v,typeof(Human));

解决方案 »

  1.   


    我这么改了,还是不行啊,一样的错误:    class Program
        {
            static void Main(string[] args)
            {
                string v = "abc";
                Human h = (Human)TypeDescriptor.GetConverter(typeof(string)).ConvertTo(v, typeof(Human));
            }
        }Unhandled Exception: System.NotSupportedException: 'StringConverter' is unable to convert 'System.String' to 'ConsoleApplication1.Human'.
       at System.ComponentModel.TypeConverter.GetConvertToException(Object value, Type destinationType)
       at System.ComponentModel.TypeConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
       at System.ComponentModel.TypeConverter.ConvertTo(Object value, Type destinationType)
       at ConsoleApplication1.Program.Main(String[] args) in d:\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 164
      

  2.   

    楼主傻了啵,明明重载了的是 ConvertFrom 方法,是从 string 转到 Human 的,临了居然调用 ConvertTo 了?