How could I implement the .NET 4\'s Enum.TryParse method in .NET 3.5?
public static bool TryParse(string
It won't be a static method on Enum (static extension methods don't quite make sense), but it should work
public static class EnumHelpers
{
public static bool TryParse(string value, out TEnum result)
where TEnum : struct
{
try
{
result = (TEnum)Enum.Parse(typeof(TEnum), value);
}
catch
{
result = default;
return false;
}
return true;
}
}