コード例 #1
0
        public void PropertyAccessModiferOnNotNullableMember()
        {
            IExpressionRewriter modifier = new PropertyAccessRewriter();
            Expression <Func <Member, int> > expression = m => m.GroupId2;

            Expression newBody = modifier.Rewrite(expression.Body);

            expression = ExpressionUtils.ChangeBody(expression, newBody);

            int?result = expression.Compile().Invoke(null);
        }
コード例 #2
0
        public void PropertyAccessModiferOnCastedMember()
        {
            IExpressionRewriter modifier = new PropertyAccessRewriter();
            Expression <Func <Member, int?> > expression = m => (int?)m.GroupId2;

            Expression newBody = modifier.Rewrite(expression.Body);

            expression = ExpressionUtils.ChangeBody(expression, newBody);

            int?result = expression.Compile().Invoke(null);

            Assert.IsNull(result);
        }
コード例 #3
0
        public void PropertyAccessModiferOnConvertedStaticMember()
        {
            IExpressionRewriter            modifier   = new PropertyAccessRewriter();
            Expression <Func <DateTime?> > expression = () => (DateTime?)DateTime.Now;

            Expression newBody = modifier.Rewrite(expression.Body);

            expression = ExpressionUtils.ChangeBody(expression, newBody);

            DateTime?result = expression.Compile().Invoke();

            Assert.IsNotNull(result);
        }
コード例 #4
0
        public void PropertyAccessModiferOnMappedNullableMember()
        {
            IExpressionRewriter modifier = new PropertyAccessRewriter();
            Expression <Func <Member, string> > expression = m => m.GroupId == null ? "null" : "not null";

            Expression newBody = modifier.Rewrite(expression.Body);

            expression = ExpressionUtils.ChangeBody(expression, newBody);

            string result = expression.Compile().Invoke(null);

            Assert.AreEqual("null", result);
        }
コード例 #5
0
        public void PropertyAccessModiferOnStaticMember()
        {
            IExpressionRewriter         modifier   = new PropertyAccessRewriter();
            Expression <Func <string> > expression = () => PropertyAccessModifierFixture.Static;

            Expression newBody = modifier.Rewrite(expression.Body);

            expression = ExpressionUtils.ChangeBody(expression, newBody);

            string result = expression.Compile().Invoke();

            Assert.IsNotNull(result);
        }