public static T Convert(String value)
{
return (T)Convert.ChangeType(value, typeof(T));
}
public enum Category
{
Empty,
Name
Use Enum.Parse method for this.
public static T Convert<T>(String value)
{
if (typeof(T).IsEnum)
return (T)Enum.Parse(typeof(T), value);
return (T)Convert.ChangeType(value, typeof(T));
}
.Net Core version :
public static T Convert<T>(string value)
{
if (typeof(T).GetTypeInfo().IsEnum)
return (T)Enum.Parse(typeof(T), value);
return (T)System.Convert.ChangeType(value, typeof(T));
}