sdk/dotnet/src/Microsoft.Datasync.Client/Query/QueryDescription.cs
/// <summary>
/// Parses an OData query and creates a <see cref="QueryDescription"/> instance.
/// </summary>
/// <param name="tableName">The name of the table for the query.</param>
/// <param name="query">The OData query string.</param>
/// <returns>The <see cref="QueryDescription"/> for the query.</returns>
Parses an OData query and creates a  instance.
Parses an OData query and creates a instance .
public static QueryDescription Parse(string tableName, string query = null)
        {
            bool includeTotalCount = false;
            int? top = null, skip = null;
            string[] selection = null;
            QueryNode filter = null;
            IList<OrderByNode> orderings = null;
            query ??= string.Empty;
            IDictionary<string, string> parameters = query.Split('&')
                .Select(part => part.Split(new[] { '=' }, 2))
                .ToDictionary(x => Uri.UnescapeDataString(x[0]), x => x.Length > 1 ? Uri.UnescapeDataString(x[1]) : string.Empty);
            foreach (var parameter in parameters)
            {
                if (string.IsNullOrEmpty(parameter.Key))
                {
                    continue;
                }
                switch (parameter.Key)
                {
                    case ODataOptions.Filter:
                        filter = ODataExpressionParser.ParseFilter(parameter.Value);
                        break;
                    case ODataOptions.OrderBy:
                        orderings = ODataExpressionParser.ParseOrderBy(parameter.Value);
                        break;
                    case ODataOptions.Skip:
                        skip = Int32.Parse(parameter.Value);
                        break;
                    case ODataOptions.Top:
                        top = Int32.Parse(parameter.Value);
                        break;
                    case ODataOptions.Select:
                        selection = parameter.Value.Split(',');
                        break;
                    case ODataOptions.InlineCount:
                        includeTotalCount = parameter.Value.Equals("true");
                        break;
                    default:
                        break;
                }
            }
            return new QueryDescription(tableName)
            {
                Filter = filter,
                IncludeTotalCount = includeTotalCount,
                Ordering = new List<OrderByNode>(orderings ?? Array.Empty<OrderByNode>()),
                Projections = new(),
                Selection = new List<string>(selection ?? Array.Empty<string>()),
                Skip = skip,
                Top = top,
            };
        }
public static QueryDescription Parse ( string tableName , string query = null ) { bool includeTotalCount = false ; int ? top = null , skip = null ; string [ ] selection = null ; QueryNode filter = null ; IList < OrderByNode > orderings = null ; query ??= string . Empty ; IDictionary < string , string > parameters = query . Split ( ' ' ) . Select ( part => part . Split ( new [ ] { ' ' } , 2 ) ) . ToDictionary ( x => Uri . UnescapeDataString ( x [ 0 ] ) , x => x . Length > 1 ? Uri . UnescapeDataString ( x [ 1 ] ) : string . Empty ) ; foreach ( var parameter in parameters ) { if ( string . IsNullOrEmpty ( parameter . Key ) ) { continue ; } switch ( parameter . Key ) { case ODataOptions . Filter : filter = ODataExpressionParser . ParseFilter ( parameter . Value ) ; break ; case ODataOptions . OrderBy : orderings = ODataExpressionParser . ParseOrderBy ( parameter . Value ) ; break ; case ODataOptions . Skip : skip = Int32 . Parse ( parameter . Value ) ; break ; case ODataOptions . Top : top = Int32 . Parse ( parameter . Value ) ; break ; case ODataOptions . Select : selection = parameter . Value . Split ( ' ' ) ; break ; case ODataOptions . InlineCount : includeTotalCount = parameter . Value . Equals ( " " ) ; break ; default : break ; } } return new QueryDescription ( tableName ) { Filter = filter , IncludeTotalCount = includeTotalCount , Ordering = new List < OrderByNode > ( orderings ?? Array . Empty < OrderByNode > ( ) ) , Projections = new ( ) , Selection = new List < string > ( selection ?? Array . Empty < string > ( ) ) , Skip = skip , Top = top , } ; }
Parses an OData query and creates a  instance.
Parses an OData query and creates a instance .
// Skip this argument - it isn't important.
The  for the query.
The for the query .
tableName
string
The name of the table for the query.
The name of the table for the query .
query
string
The OData query string.
The OData query string .