代码片段——泛型类型转换
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))); } }