Wanted to post an update on this. I've tested and verified that fix and that it still works fine when used under framework 4.0, so that will be pushed to our repository shortly.
In addition, here is a 1:1 replacement for the ToEnum method that doesn't require any other code changes:
/// <summary>
/// Converts a string to its enum representation.
/// </summary>
/// <typeparam name="T">Enum type.</typeparam>
/// <param name="s">String to convert.</param>
/// <returns>Returns the enum value.</returns>
public static T ToEnum<T>(this string s) where T : struct, IConvertible
{
T t;
try
{
t = (T)Enum.Parse(typeof(T), s, true);
return t;
} catch
{
return default(T);
}
}
Wanted to add that for anyone else who may need to implement this to be compatible with Framework 3.5. I'll also discuss this with the team and see if we can't get this update into the repo properly.
... View more