Enum.PaseUnstrict

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));

Description

Permit Enum Parse everytime with valid values using a defaultValue param

Details

Double click on the code to select all.

 

;