public static T ConvertTo<T>(object value)
{
if (value == null)
{
return default(T);
}
var type = typeof(T);
if ((type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>))))
{
return (T)Convert.ChangeType(value, type.GetGenericArguments()[0]);
}
else
{
return (T)Convert.ChangeType(value, type);
}
}
时间: 2024-10-09 09:35:02