예제 #1
0
        public void Test_SpecialCase()
        {
            var list  = new List <Foo>();
            var query = new QueryModel();

            query.Add(new Condition()
            {
                Field = "p2", Op = Operation.Equals, Value = 1
            });
            query.Add(new Condition()
            {
                Field = "p2", Op = Operation.StdIn, Value = new List <int> {
                    1, 2, 3
                }
            });
            var lambdaExp = LambdaExpressionBuilder.BuildLambda <Foo>(query);
            var lambda    = lambdaExp.Compile();

            list = list.Where(lambda).ToList();
        }
예제 #2
0
        /// <summary>
        /// 将一组key=value添加入QueryModel.Items
        /// </summary>
        /// <param name="model">QueryModel</param>
        /// <param name="key">当前项的HtmlName</param>
        /// <param name="val">当前项的值</param>
        static void AddSearchItem(QueryModel model, string key, object val)
        {
            string field = "", prefix = "", orGroup = "", method = "";
            var    keywords = key.Split(']', ')', '}');

            //将Html中的name分割为我们想要的几个部分
            foreach (var keyword in keywords)
            {
                if (Char.IsLetterOrDigit(keyword[0]))
                {
                    field = keyword;
                }
                var last = keyword.Substring(1);
                if (keyword[0] == '(')
                {
                    prefix = last;
                }
                if (keyword[0] == '[')
                {
                    method = last;
                }
                if (keyword[0] == '{')
                {
                    orGroup = last;
                }
            }
            if (string.IsNullOrEmpty(method))
            {
                return;
            }
            OperationType opType;

            if (!FilterSettings.Dict.TryGetValue(method, out opType))
            {
                return;
            }
            if (!string.IsNullOrEmpty(field))
            {
                var item = new Filter
                {
                    Field     = field,
                    Value     = val,
                    Prefix    = prefix,
                    OrGroup   = orGroup,
                    Operation = opType
                };
                model.Add(item);
            }
        }