示例#1
0
        public void TestMethodWithDefaultCriteria1()
        {
            var lst1 = Enumerable.Range(1, 100).Select(i => new Class1
            {
                MyProperty1 = i,
                MyProperty2 = i.ToString(),
                MyProperty3 = new DateTime(2000, 1, 1).AddDays(i)
            }).AsQueryable();
            var mcb = MatchCriteriaBuilder.Create(
                (Class3 i) => new { A = i.MyProperty10.MyProperty4, B = i.MyProperty8 },
                (Class1 i) => new { A = i.MyProperty1, B = i.MyProperty2 },
                i => i.MyProperty1 % 2 == 0
                );
            var ce = mcb.GetCriteriaExpression(new Class3 {
                MyProperty10 = new Class2 {
                    MyProperty4 = 1
                }, MyProperty8 = "1"
            });

            var res = lst1.FirstOrDefault(ce);

            Assert.AreEqual(null, res);

            ce = mcb.GetCriteriaExpression(new Class3 {
                MyProperty10 = new Class2 {
                    MyProperty4 = 2
                }, MyProperty8 = "2"
            });
            res = lst1.FirstOrDefault(ce);
            Assert.AreEqual(new DateTime(2000, 1, 1).AddDays(2), res.MyProperty3);
        }
示例#2
0
        public void TestMethod1()
        {
            var lst1 = Enumerable.Range(1, 100).Select(i => new Class1
            {
                MyProperty1 = i,
                MyProperty2 = i.ToString(),
                MyProperty3 = new DateTime(2000, 1, 1).AddDays(i)
            }).AsQueryable();
            var mcb = MatchCriteriaBuilder.Create(
                (Class3 i) => new { A = i.MyProperty10.MyProperty4, B = i.MyProperty8 },
                (Class1 i) => new { A = i.MyProperty1, B = i.MyProperty2 }
                );
            var p = new Class3 {
                MyProperty10 = new Class2 {
                    MyProperty4 = 1
                }, MyProperty8 = "1"
            };
            var ce  = mcb.GetCriteriaExpression(p);
            var ceT = ((Expression <Func <Class1, bool> >)((Class1 i) => i.MyProperty1 == p.MyProperty10.MyProperty4 && i.MyProperty2 == p.MyProperty8));
            var res = lst1.FirstOrDefault(ce);

            Assert.AreEqual(new DateTime(2000, 1, 1).AddDays(1), res.MyProperty3);
        }