Esempio n. 1
0
        public Predicate <object> GetEvaluator <TModel>(params Expression <Func <TModel, TExpected, bool> >[] mathings)
        {
            // On pourrait imaginer un algo qui match par convention de nom

            // On récupère les noms de propriété du model expected
            Dictionary <string, string> _filters = new Dictionary <string, string>();

            foreach (var item in mathings)
            {
                var nameModels = MemberFind.Get(item);

                var nameModel = nameModels
                                .Where(c => c.DeclaringType == typeof(TExpected))
                                .Select(c => c.Name)
                                .First();

                var nameModel2 = nameModels
                                 .Where(c => c.DeclaringType == typeof(TModel))
                                 .Select(c => c.Name)
                                 .First();

                _filters.Add(nameModel, nameModel2);
            }

            var filter             = new Filter <TExpected, TModel>(_tree, _filters);
            Predicate <object> fnc = a => filter._node.Evaluate(a);

            return(fnc);
        }
Esempio n. 2
0
        /// <summary>
        /// Sort on specific properties
        /// </summary>
        /// <param name="properties"></param>
        public Tree(params Expression <Func <TExpected, object> >[] properties)
        {
            HashSet <string>    hashDedoublon = new HashSet <string>();
            List <PropertyInfo> props         = new List <PropertyInfo>();

            foreach (var item in properties)
            {
                var member = MemberFind.Get(item).First();
                if (hashDedoublon.Add(member.Name))
                {
                    props.Add(member);
                }
            }

            // On ajoute les proprietes manquantes
            var p2 = typeof(TExpected).GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var member in p2)
            {
                if (hashDedoublon.Add(member.Name))
                {
                    props.Add(member);
                }
            }

            _properties = props.ToArray();
        }
Esempio n. 3
0
        private static PropertyInfo[] GetProperties <TModel>(Expression <Func <TModel, object> >[] properties)
        {
            HashSet <string>    hashDedoublon = new HashSet <string>();
            List <PropertyInfo> props         = new List <PropertyInfo>();

            foreach (var item in properties)
            {
                var member = MemberFind.Get(item).First();
                if (hashDedoublon.Add(member.Name))
                {
                    props.Add(member);
                }
            }

            return(props.ToArray());
        }