public static T To(this object input) where T : IConvertible { string type = typeof(T).Name; TypeCode typecode; if (!Enum.TryParse(type, out typecode)) throw new ArgumentException("Could not convert!"); return (T)Convert.ChangeType(input, typecode); }
No comments:
Post a Comment