枚举的强制类型转化通用泛型方法
public static T ParseEnum<T>(object oValue, T defaultValue) { if (oValue == null) return defaultValue; if (oValue.Equals('\0')) return (T)Convert.ChangeType(0, typeof(T)); if (oValue is T) return (T)oValue; var sValue = oValue.ToString(); if (string.IsNullOrEmpty(sValue)) return defaultValue; try { var o = Enum.Parse(typeof(T), sValue); if (o == null) return defaultValue; return (T)o; } catch (Exception error) { return defaultValue; } }