예제 #1
0
        public static Func <T, bool> GenerateFilters <T>(Control.ControlCollection controls, string valueProperty, string namesProperty)
        {
            var andBuilder = PredicateBuilder.True <T>();

            foreach (var control in controls)
            {
                if (control == null || !control.HasProperty(valueProperty))
                {
                    continue;
                }

                var value = control.GetStringProperty(valueProperty);
                if (value.ExIsNullOrEmpty())
                {
                    continue;
                }

                var properties = control.GetValueOfProperty(namesProperty);
                if (properties == null)
                {
                    continue;
                }

                var orBuilder = PredicateBuilder.False <T>();
                foreach (var propertyName in properties.ExToStringOrEmpty().Split(','))
                {
                    var name = propertyName;
                    orBuilder = orBuilder.Or(item => GeneralUtils.FilterCheck(item, name, value));
                }

                andBuilder = andBuilder.And(orBuilder);
            }

            return(andBuilder.Compile());
        }