using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Opsoft.NetCore.O3App.Shared { public static class Int32Extensions { public static TOut ToEnum(this int value) { var outputType = typeof(TOut); if (outputType.IsEnum) { if (outputType.IsEnumDefined(value)) { var obj = Enum.ToObject(outputType, value); if (obj != null) { return (TOut)obj; } } } return default(TOut); } /// /// 检查某值是否在指定范围内 /// public static bool Between(this int value, int min, int max) { return value >= min && value <= max; } public static bool In(this int source, params int[] values) { return values.Contains(source); } public static bool In(this int source, params Enum[] enums) { return Array.Exists(enums, current => Convert.ToInt32(current) == source); } } }