Пример #1
0
        public void roundtrip_Constant_string()
        {
            ConstantExpression expr = Expression.Constant("a");
            var result = (ConstantExpression)SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, iftFactory));

            AssertExpressions.AreEqual(result, expr);
        }
Пример #2
0
        public void roundtrip_Constant_object()
        {
            ISomething         value = new Something();
            ConstantExpression expr  = Expression.Constant(value);
            var result = (ConstantExpression)SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, iftFactory));

            AssertExpressions.AreEqual(result, expr);
        }
Пример #3
0
        public void roundtrip_Constant_interface()
        {
            ISomething         value = new Something();
            ConstantExpression expr  = Expression.Constant(value, typeof(ISomething));
            var result = (ConstantExpression)SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, iftFactory));

            AssertExpressions.AreEqual(result, expr);
            Assert.That(result.Type, Is.EqualTo(typeof(ISomething)));
        }
Пример #4
0
 private static void CollectionsAreEqual <T>(ReadOnlyCollection <T> x, ReadOnlyCollection <T> y)
     where T : Expression
 {
     Assert.That(x.Count, Is.EqualTo(y.Count));
     for (int i = 0; i < x.Count; i++)
     {
         AssertExpressions.AreEqual(x[i], y[i]);
     }
 }
Пример #5
0
            protected override int VisitExpression(MemberExpression expr)
            {
                var other = (MemberExpression)second;

                CompareBasicProperties(expr, other);
                AssertExpressions.AreEqual(expr.Expression, other.Expression);
                Assert.AreEqual(expr.Member, other.Member);
                return(0);
            }
Пример #6
0
            protected override int VisitExpression(LambdaExpression expr)
            {
                var other = (LambdaExpression)second;

                CompareBasicProperties(expr, other);
                AssertExpressions.AreEqual(expr.Body, other.Body);
                CollectionsAreEqual(expr.Parameters, other.Parameters);
                return(0);
            }
Пример #7
0
        public void roundtrip_MemberAccess_to_string_Length_property_should_optimize_constness()
        {
            string           testString = "farglbl";
            var              objExpr    = Expression.Constant(testString);
            MemberExpression expr       = Expression.MakeMemberAccess(objExpr, typeof(string).GetMember("Length").First());

            var result = SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, scope.Resolve <InterfaceType.Factory>()));

            AssertExpressions.AreEqual(result, Expression.Constant(testString.Length));
        }
Пример #8
0
            protected override int VisitExpression(ConditionalExpression expr)
            {
                var other = (ConditionalExpression)second;

                CompareBasicProperties(expr, other);
                AssertExpressions.AreEqual(expr.IfFalse, other.IfFalse);
                AssertExpressions.AreEqual(expr.IfTrue, other.IfTrue);
                AssertExpressions.AreEqual(expr.Test, other.Test);
                return(0);
            }
Пример #9
0
            protected override int VisitExpression(MethodCallExpression expr)
            {
                var other = (MethodCallExpression)second;

                CompareBasicProperties(expr, other);
                CollectionsAreEqual(expr.Arguments, other.Arguments);
                Assert.AreEqual(expr.Method, other.Method);
                AssertExpressions.AreEqual(expr.Object, other.Object);
                return(0);
            }
Пример #10
0
            protected override int VisitExpression(UnaryExpression expr)
            {
                var other = (UnaryExpression)second;

                CompareBasicProperties(expr, other);
                Assert.AreEqual(expr.IsLifted, other.IsLifted);
                Assert.AreEqual(expr.IsLiftedToNull, other.IsLiftedToNull);
                Assert.AreEqual(expr.Method, other.Method);
                AssertExpressions.AreEqual(expr.Operand, other.Operand);
                return(0);
            }
Пример #11
0
            protected override int VisitExpression(BinaryExpression expr)
            {
                var other = (BinaryExpression)second;

                CompareBasicProperties(expr, other);
                AssertExpressions.AreEqual(expr.Conversion, other.Conversion);
                Assert.AreEqual(expr.IsLifted, other.IsLifted);
                Assert.AreEqual(expr.IsLiftedToNull, other.IsLiftedToNull);
                AssertExpressions.AreEqual(expr.Left, other.Left);
                Assert.AreEqual(expr.Method, other.Method);
                AssertExpressions.AreEqual(expr.Right, other.Right);
                return(0);
            }