Пример #1
0
        public static List <TEnum> GetValid <TEnum>(DateTime date, Expression <Func <ExternalCodeAttribute, bool> > expression = null) where TEnum : Enum
        {
            Func <ExternalCodeAttribute, bool> expcompiled = null;

            if (expression != null)
            {
                expcompiled = expression.Compile();
            }


            List <TEnum> result = new();

            foreach (var value in Enum.GetValues(typeof(TEnum)))
            {
                var attr = ExternalCodeAttributeExtensions.GetExternalCodeAttribute(value);
                if (
                    (string.IsNullOrWhiteSpace(attr.ValidFromDate) &&
                     (
                         string.IsNullOrWhiteSpace(attr.ValidToDate) ||
                         date <= DateTime.Parse(attr.ValidToDate)
                     )
                    )
                    ||
                    (date >= DateTime.Parse(attr.ValidFromDate) &&
                     (
                         string.IsNullOrWhiteSpace(attr.ValidToDate) ||
                         date <= DateTime.Parse(attr.ValidToDate)
                     )
                    )
                    )
                {
                    if (expcompiled is null || expcompiled.Invoke(attr))
                    {
                        result.Add((TEnum)value);
                    }
                }
            }
            return(result);
        }
Пример #2
0
 public static string GetCode(this Enum enumerate)
 {
     return(ExternalCodeAttributeExtensions.GetExternalCodeAttribute(enumerate)?.Code);
 }