示例#1
0
        public void CombineMemberInitTestMultiParam()
        {
            Expression <Func <Client, int, ClientDTO> > a = (x, y) => new ClientDTO
            {
                Name = "Hello " + x.Name + " " + y,
                Age  = x.Age
            };

            Expression <Func <Client, int, ClientDTO> > b = (x, y) => new ClientDTO
            {
                LegalDrinking = true,
                Age           = x.Age + y
            };

            var comb = LinqEx.CombineMemberInitExpression(a, b);
            var res  = comb.Compile()(new Client
            {
                Name = "Rafael",
                Age  = 20,
            }, 3);

            Assert.AreEqual("Hello Rafael 3", res.Name);
            Assert.AreEqual(23, res.Age);
            Assert.AreEqual(true, res.LegalDrinking);
        }
示例#2
0
        public void CombineMemberInitTest()
        {
            Expression <Func <Client, ClientDTO> > a = x => new ClientDTO
            {
                Name = "Hello " + x.Name,
                Age  = x.Age
            };

            Expression <Func <Client, ClientDTO> > b = x => new ClientDTO
            {
                LegalDrinking = true,
                Age           = x.Age + 1
            };

            var comb = LinqEx.CombineMemberInitExpression(a, b);
            var res  = comb.Compile()(new Client
            {
                Name = "Rafael",
                Age  = 20,
            });

            Assert.AreEqual("Hello Rafael", res.Name);
            Assert.AreEqual(21, res.Age);
            Assert.AreEqual(true, res.LegalDrinking);
        }