< Summary

Class:Azure.Data.Tables.Queryable.LinqExpressionVisitor
Assembly:Azure.Data.Tables
File(s):C:\Git\azure-sdk-for-net\sdk\tables\Azure.Data.Tables\src\Queryable\LinqExpressionVisitor.cs
Covered lines:50
Uncovered lines:7
Coverable lines:57
Total lines:193
Line coverage:87.7% (50 of 57)
Covered branches:68
Total branches:82
Branch coverage:82.9% (68 of 82)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Visit(...)-91.67%85.42%
VisitUnary(...)-100%100%
VisitBinary(...)-87.5%80%
VisitConstant(...)-100%100%
VisitParameter(...)-100%100%
VisitMemberAccess(...)-75%50%
VisitMethodCall(...)-100%100%
VisitExpressionList(...)-76.92%80%
VisitLambda(...)-100%100%
VisitInvocation(...)-80%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\tables\Azure.Data.Tables\src\Queryable\LinqExpressionVisitor.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Collections.ObjectModel;
 7using System.Globalization;
 8using System.Linq.Expressions;
 9
 10namespace Azure.Data.Tables.Queryable
 11{
 12    internal abstract class LinqExpressionVisitor
 13    {
 14        internal virtual Expression Visit(Expression exp)
 15        {
 1810816            if (exp == null)
 17            {
 114818                return exp;
 19            }
 20
 1696021            switch (exp.NodeType)
 22            {
 23                case ExpressionType.UnaryPlus:
 24                case ExpressionType.Negate:
 25                case ExpressionType.NegateChecked:
 26                case ExpressionType.Not:
 27                case ExpressionType.Convert:
 28                case ExpressionType.ConvertChecked:
 29                case ExpressionType.ArrayLength:
 30                case ExpressionType.Quote:
 31                case ExpressionType.TypeAs:
 30032                    return VisitUnary((UnaryExpression)exp);
 33                case ExpressionType.Add:
 34                case ExpressionType.AddChecked:
 35                case ExpressionType.Subtract:
 36                case ExpressionType.SubtractChecked:
 37                case ExpressionType.Multiply:
 38                case ExpressionType.MultiplyChecked:
 39                case ExpressionType.Divide:
 40                case ExpressionType.Modulo:
 41                case ExpressionType.Power:
 42                case ExpressionType.And:
 43                case ExpressionType.AndAlso:
 44                case ExpressionType.Or:
 45                case ExpressionType.OrElse:
 46                case ExpressionType.LessThan:
 47                case ExpressionType.LessThanOrEqual:
 48                case ExpressionType.GreaterThan:
 49                case ExpressionType.GreaterThanOrEqual:
 50                case ExpressionType.Equal:
 51                case ExpressionType.NotEqual:
 52                case ExpressionType.Coalesce:
 53                case ExpressionType.ArrayIndex:
 54                case ExpressionType.RightShift:
 55                case ExpressionType.LeftShift:
 56                case ExpressionType.ExclusiveOr:
 459257                    return VisitBinary((BinaryExpression)exp);
 58                case ExpressionType.Constant:
 298859                    return VisitConstant((ConstantExpression)exp);
 60                case ExpressionType.Parameter:
 298861                    return VisitParameter((ParameterExpression)exp);
 62                case ExpressionType.MemberAccess:
 318063                    return VisitMemberAccess((MemberExpression)exp);
 64                case ExpressionType.Call:
 106465                    return VisitMethodCall((MethodCallExpression)exp);
 66                case ExpressionType.Lambda:
 184067                    return VisitLambda((LambdaExpression)exp);
 68                case ExpressionType.Invoke:
 869                    return VisitInvocation((InvocationExpression)exp);
 70                default:
 071                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "The expression type {0} i
 72            }
 73        }
 74
 75        internal virtual Expression VisitUnary(UnaryExpression u)
 76        {
 28477            Expression operand = Visit(u.Operand);
 28478            if (operand != u.Operand)
 79            {
 880                return Expression.MakeUnary(u.NodeType, operand, u.Type, u.Method);
 81            }
 82
 27683            return u;
 84        }
 85
 86        internal virtual Expression VisitBinary(BinaryExpression b)
 87        {
 344488            Expression left = Visit(b.Left);
 344489            Expression right = Visit(b.Right);
 344490            Expression conversion = Visit(b.Conversion);
 344491            if (left != b.Left || right != b.Right || conversion != b.Conversion)
 92            {
 83093                if (b.NodeType == ExpressionType.Coalesce && b.Conversion != null)
 94                {
 095                    return Expression.Coalesce(left, right, conversion as LambdaExpression);
 96                }
 97                else
 98                {
 83099                    return Expression.MakeBinary(b.NodeType, left, right, b.IsLiftedToNull, b.Method);
 100                }
 101            }
 102
 2614103            return b;
 104        }
 105
 106        internal virtual Expression VisitConstant(ConstantExpression c)
 107        {
 2180108            return c;
 109        }
 110
 111        internal virtual Expression VisitParameter(ParameterExpression p)
 112        {
 2400113            return p;
 114        }
 115
 116        internal virtual Expression VisitMemberAccess(MemberExpression m)
 117        {
 2592118            Expression exp = Visit(m.Expression);
 2592119            if (exp != m.Expression)
 120            {
 0121                return Expression.MakeMemberAccess(exp, m.Member);
 122            }
 123
 2592124            return m;
 125        }
 126
 127        internal virtual Expression VisitMethodCall(MethodCallExpression m)
 128        {
 852129            Expression obj = Visit(m.Object);
 130
 852131            IEnumerable<Expression> args = VisitExpressionList(m.Arguments);
 852132            if (obj != m.Object || args != m.Arguments)
 133            {
 40134                return Expression.Call(obj, m.Method, args);
 135            }
 136
 812137            return m;
 138        }
 139
 140        internal virtual ReadOnlyCollection<Expression> VisitExpressionList(ReadOnlyCollection<Expression> original)
 141        {
 860142            List<Expression> list = null;
 4300143            for (int i = 0, n = original.Count; i < n; i++)
 144            {
 860145                Expression p = Visit(original[i]);
 860146                if (list != null)
 147                {
 0148                    list.Add(p);
 149                }
 860150                else if (p != original[i])
 151                {
 40152                    list = new List<Expression>(n);
 0153                    for (int j = 0; j < i; j++)
 154                    {
 0155                        list.Add(original[j]);
 156                    }
 157
 40158                    list.Add(p);
 159                }
 160            }
 161
 860162            if (list != null)
 163            {
 40164                return new ReadOnlyCollection<Expression>(list);
 165            }
 166
 820167            return original;
 168        }
 169
 170        internal virtual Expression VisitLambda(LambdaExpression lambda)
 171        {
 1380172            Expression body = Visit(lambda.Body);
 1380173            if (body != lambda.Body)
 174            {
 424175                return Expression.Lambda(lambda.Type, body, lambda.Parameters);
 176            }
 177
 956178            return lambda;
 179        }
 180
 181        internal virtual Expression VisitInvocation(InvocationExpression iv)
 182        {
 8183            IEnumerable<Expression> args = VisitExpressionList(iv.Arguments);
 8184            Expression expr = Visit(iv.Expression);
 8185            if (args != iv.Arguments || expr != iv.Expression)
 186            {
 0187                return Expression.Invoke(expr, args);
 188            }
 189
 8190            return iv;
 191        }
 192    }
 193}