示例#1
0
        public void TestGetValue_Instance()
        {
            var test = new Sample
            {
                StringValue = "a", BoolValue = true,
                Test2       = new Sample2 {
                    StringValue = "b", Test3 = new Sample3 {
                        StringValue = "c"
                    }
                }
            };

            Expression <Func <string> > expression = () => test.StringValue;

            Assert.Equal("a", Lambda.GetValue(expression));

            Expression <Func <string> > expression2 = () => test.Test2.StringValue;

            Assert.Equal("b", Lambda.GetValue(expression2));

            Expression <Func <string> > expression3 = () => test.Test2.Test3.StringValue;

            Assert.Equal("c", Lambda.GetValue(expression3));

            Expression <Func <bool> > expression4 = () => test.BoolValue;

            Assert.True(Convert.ToBool(Lambda.GetValue(expression4)));
        }
示例#2
0
        public void TestGetValue_NewGuid()
        {
            Expression <Func <Sample, bool> > expression = t => t.GuidValue == Guid.NewGuid();
            var value = Lambda.GetValue(expression);

            Assert.NotEqual(Guid.Empty, Convert.ToGuid(value));
        }
示例#3
0
        public void TestGetValue_DateTimeNow()
        {
            Expression <Func <Sample, bool> > expression = t => t.DateValue == DateTime.Now;
            var value = Lambda.GetValue(expression);

            Assert.NotNull(Convert.ToDateOrNull(value));
        }