/// <summary> /// 获取枚举对应的值 /// </summary> /// <typeparam name="T">枚举类型</typeparam> /// <param name="enumName">枚举对应值的名</param> /// <returns>枚举对象对应的值</returns> public static int GetEnumValue<T>(this object enumName) { return (int)enumName.GetEnumObj<T>(); } /// <summary> /// 获取枚举对象 /// </summary> /// <typeparam name="T">枚举类型</typeparam> /// <param name="enumName">枚举对应值的名</param> /// <returns>枚举对象</returns> private static object GetEnumObj<T>(this object enumName) { string enumNameValue = enumName.toString(); return (T)Enum.Parse(typeof(T), enumNameValue); }
时间: 2024-10-13 12:17:16