Enum.PaseUnstrict
Permit Enum Parse everytime with valid values using a defaultValue param
Source
public static object ParseUnstrict(this Type enumtype, string value, object defaultValue) {
object res = defaultValue;
try {
if(value == "") {
return res;
}
res = System.Enum.Parse(enumtype, value);
} catch(Exception ex) {
//do nothing
}
return res;
}
Example
EStatus status = (EStatus)Enum.ParseUnstrict(typeof(EStatus), value, EStatus.unknown));