using System;
using System.ComponentModel;
public class Convertors
{
///
/// See Convert.ChangeType.
///
/// New type, may be Nullable.
/// Object
/// Typed object.
public static T ChangeType(object value)
{
Type conversionType = typeof(T);
if (conversionType.IsGenericType && conversionType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
if (value == null)
{
return default(T);
}
else
{
NullableConverter nullableConverter = new NullableConverter(conversionType);
conversionType = nullableConverter.UnderlyingType;
}
}
return (T)Convert.ChangeType(value, conversionType);
}
}