public static T ObjectToEnum<T>(object o) { try { return (T)Enum.Parse(typeof(T), o.ToString(), true); }catch { return default(T); //retrun 0 // your code } }