using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Sleis.Utility { public static class ConversionUtility { public static T ConvertTo(this IConvertible obj) { return ConvertType(obj); } public static T ConvertTo(this object obj) { return ConvertType(obj); } private static T ConvertType(object obj) { Type t = typeof(T); Type u = Nullable.GetUnderlyingType(t); if (u != null) { if (obj == null) return default(T); return (T)Convert.ChangeType(obj, u); } else { return (T)Convert.ChangeType(obj, t); } } } }