public static class TConverter
{
    public static T ChangeType<T>(object value)
    {
        return (T)ChangeType(typeof(T), value);
    }
    public static object ChangeType(Type t, object value)
    {
        TypeConverter tc = TypeDescriptor.GetConverter(t);
        return tc.ConvertFrom(value);
    }
    public static void RegisterTypeConverter<T, TC>() where TC : TypeConverter
    {
        TypeDescriptor.AddAttributes(typeof(T), new TypeConverterAttribute(typeof(TC)));
    }
}

相关文章:

  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2021-12-14
  • 2022-01-20
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2022-02-12
  • 2022-12-23
  • 2021-06-20
  • 2021-08-01
  • 2021-06-12
相关资源
相似解决方案