Say I have an enum,
public enum Colours
{
Red,
Blue
}
The only way I can see of parsing them is doing something like:
No, there's no "no-throw" method for this (a la TryParse that some other classes have).
However, you could easily write your own so as to encapsulate the try-catch logic (or the IsDefined check) in one helper method so it doesn't pollute your app code:
public static object TryParse(Type enumType, string value, out bool success)
{
success = Enum.IsDefined(enumType, value);
if (success)
{
return Enum.Parse(enumType, value);
}
return null;
}