Вы можете заключить это в метод расширения, чтобы сделать вызов проще:
public static T ToEnum<T>(this string value) {
if (string.IsNullOrWhiteSpace(value)) {
throw new ArgumentNullException("Cannot convert null or empty string to an enum");
}
// Get enum from the built-in Parse method
return (T)Enum.Parse(typeof(T), value, true);
}
Затем вызовите
myValue.ToEnum<EnumNameHere>();
Чтобы получить перечисление