private ExcelStyleFilterElementOperatorItem CreateLastYearsOperator()
        {
            const string CustomFunctionName = "LastYears";
            var          currentYear        = DateTime.Now.Year;
            ICustomFunctionOperatorBrowsable customFunction = CustomFunctionFactory.Create(CustomFunctionName,
                                                                                           (DateTime date, int threshold) =>
            {
                return(currentYear >= date.Year && currentYear - date.Year <= threshold);
            }
                                                                                           );

            CriteriaOperator.RegisterCustomFunction(customFunction);
            var customFunctionEditSettings = new BaseEditSettings[] {
                new TextEditSettings {
                    MaskType = MaskType.Numeric,
                    Mask     = "D",
                    MaskUseAsDisplayFormat = true,
                    NullText = "Enter the number of years before..."
                }
            };

            return(new ExcelStyleFilterElementOperatorItem(CustomFunctionName, customFunctionEditSettings)
            {
                Caption = "Last Years"
            });
        }
コード例 #2
0
        /// <summary>
        /// Creates and registers the custom functions used to filter the category column which typically is of type <see cref="IEnumerable{Category}"/>
        /// </summary>
        private static void CreateAndRegisterCustomFunctionOperators()
        {
            var isMemberOfCategoryFunction = CustomFunctionFactory.Create(
                IsMemberOfCategoryName,
                (IEnumerable <Category> categories, string categoryName) =>
            {
                return(categories?.Any(x => x.Name.ToString().Equals(categoryName) || x.AllSuperCategories().Any(y => y.Name.ToString().Equals(categoryName))) ?? false);
            });

            CriteriaOperator.RegisterCustomFunction(isMemberOfCategoryFunction);

            var hasCategoryAppliedFunction = CustomFunctionFactory.Create(
                HasCategoryApplied,
                (IEnumerable <Category> categories, string categoryName) =>
            {
                return(categories?.Any(x => x.Name.ToString().Equals(categoryName)) ?? false);
            });

            CriteriaOperator.RegisterCustomFunction(hasCategoryAppliedFunction);
        }