sdk/dotnet/src/Microsoft.Datasync.Client/Query/Linq/QueryTranslator.cs
/// <summary>
/// Process the core LINQ operators that are supported by a datasync service using
/// a visitor process.
/// </summary>
/// <param name="expression">The expression to visit.</param>
/// <returns>The visited expression.</returns>
Process the core LINQ operators that are supported by a datasync service using
a visitor process.
Process the core LINQ operators that are supported by a datasync service using a visitor process .
internal protected Expression VisitMethodCall(MethodCallExpression expression)
        {
            if (expression.Arguments.Count >= 1)
            {
                Expression firstArgument = expression.Arguments[0];
                if (firstArgument is MethodCallExpression methodCall && firstArgument.NodeType == ExpressionType.Call)
                {
                    VisitMethodCall(methodCall);
                }
            }
            switch (expression.Method.Name)
            {
                case "OrderBy":
                    AddOrdering(expression, ascending: true, prepend: true);
                    break;
                case "OrderByDescending":
                    AddOrdering(expression, ascending: false, prepend: true);
                    break;
                case "Select":
                    AddProjection(expression);
                    break;
                case "Skip":
                    int skipCount = QueryTranslator<T>.GetCountArgument(expression);
                    QueryDescription.Skip = QueryDescription.Skip.HasValue ? QueryDescription.Skip.Value + skipCount : skipCount;
                    break;
                case "Take":
                    int takeCount = QueryTranslator<T>.GetCountArgument(expression);
                    QueryDescription.Top = QueryDescription.Top.HasValue ? Math.Min(QueryDescription.Top.Value, takeCount) : takeCount;
                    break;
                case "ThenBy":
                    AddOrdering(expression, ascending: true, prepend: false);
                    break;
                case "ThenByDescending":
                    AddOrdering(expression, ascending: false, prepend: false);
                    break;
                case "Where":
                    AddFilter(expression);
                    break;
                default:
                    throw new NotSupportedException($"'{expression.Method.Name}' caluse in query expression is not supported.");
            }
            return expression;
        }
internal protected Expression VisitMethodCall ( MethodCallExpression expression ) { if ( expression . Arguments . Count >= 1 ) { Expression firstArgument = expression . Arguments [ 0 ] ; if ( firstArgument is MethodCallExpression methodCall && firstArgument . NodeType == ExpressionType . Call ) { VisitMethodCall ( methodCall ) ; } } switch ( expression . Method . Name ) { case " " : AddOrdering ( expression , ascending : true , prepend : true ) ; break ; case " " : AddOrdering ( expression , ascending : false , prepend : true ) ; break ; case " " : AddProjection ( expression ) ; break ; case " " : int skipCount = QueryTranslator < T > . GetCountArgument ( expression ) ; QueryDescription . Skip = QueryDescription . Skip . HasValue ? QueryDescription . Skip . Value + skipCount : skipCount ; break ; case " " : int takeCount = QueryTranslator < T > . GetCountArgument ( expression ) ; QueryDescription . Top = QueryDescription . Top . HasValue ? Math . Min ( QueryDescription . Top . Value , takeCount ) : takeCount ; break ; case " " : AddOrdering ( expression , ascending : true , prepend : false ) ; break ; case " " : AddOrdering ( expression , ascending : false , prepend : false ) ; break ; case " " : AddFilter ( expression ) ; break ; default : throw new NotSupportedException ( $" ' { expression . Method . Name } ' caluse in query expression is not supported. " ) ; } return expression ; }
Process the core LINQ operators that are supported by a datasync service using
a visitor process.
Process the core LINQ operators that are supported by a datasync service using a visitor process .
// Recurse down the target of the method call until we get to something we need to process. // Handle the method call itself.  There is only a certain list of LINQ method calls that we handle. // Note that Skip(), Take(), and non-standard LINQ calls are handled elsewhere.
The visited expression.
The visited expression .
expression
MethodCallExpression
The expression to visit.
The expression to visit .