PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/WCFWebApi/src/Microsoft.ApplicationServer.Http/Microsoft/ApplicationServer/Query/ServiceQuery.cs

#
C# | 107 lines | 67 code | 10 blank | 30 comment | 11 complexity | 45354769a3f4d5c66a7dad85d7635a49 MD5 | raw file
  1// <copyright>
  2//   Copyright (c) Microsoft Corporation.  All rights reserved.
  3// </copyright>
  4
  5namespace Microsoft.ApplicationServer.Query
  6{
  7    using System;
  8    using System.Collections.Generic;
  9    using System.Globalization;
 10    using Microsoft.ApplicationServer.Http;
 11
 12    /// <summary>
 13    /// Represents an <see cref="System.Linq.IQueryable"/>.
 14    /// </summary>
 15    internal class ServiceQuery
 16    {
 17        /// <summary>
 18        /// Gets or sets a list of query parts.
 19        /// </summary>
 20        public IEnumerable<ServiceQueryPart> QueryParts
 21        {
 22            get;
 23            set;
 24        }
 25    }
 26
 27    /// <summary>
 28    /// Represents a single query operator to be applied to a query
 29    /// </summary>
 30    internal class ServiceQueryPart
 31    {
 32        private string _queryOperator;
 33        private string _expression;
 34
 35        /// <summary>
 36        /// Public constructor
 37        /// </summary>
 38        public ServiceQueryPart()
 39        {
 40        }
 41
 42        /// <summary>
 43        /// Public constructor
 44        /// </summary>
 45        /// <param name="queryOperator">The query operator</param>
 46        /// <param name="expression">The query expression</param>
 47        public ServiceQueryPart(string queryOperator, string expression)
 48        {
 49            if (queryOperator == null)
 50            {
 51                throw new ArgumentNullException("queryOperator");
 52            }
 53            if (expression == null)
 54            {
 55                throw new ArgumentNullException("expression");
 56            }
 57
 58            if (queryOperator != "filter" && queryOperator != "orderby" &&
 59               queryOperator != "skip" && queryOperator != "top")
 60            {
 61                throw new ArgumentException(SR.InvalidQueryOperator(queryOperator), "queryOperator");
 62            }
 63
 64            this._queryOperator = queryOperator;
 65            this._expression = expression;
 66        }
 67
 68        /// <summary>
 69        /// Gets or sets the query operator. Must be one of the supported operators : "where", "orderby", "skip", or "take".
 70        /// </summary>
 71        public string QueryOperator
 72        {
 73            get
 74            {
 75                return this._queryOperator;
 76            }
 77            set
 78            {
 79                this._queryOperator = value;
 80            }
 81        }
 82
 83        /// <summary>
 84        /// Gets or sets the query expression.
 85        /// </summary>
 86        public string Expression
 87        {
 88            get
 89            {
 90                return this._expression;
 91            }
 92            set
 93            {
 94                this._expression = value;
 95            }
 96        }
 97
 98        /// <summary>
 99        /// Returns a string representation of this <see cref="ServiceQueryPart"/>
100        /// </summary>
101        /// <returns>The string representation of this <see cref="ServiceQueryPart"/></returns>
102        public override string ToString()
103        {
104            return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}={1}", this.QueryOperator, this.Expression);
105        }
106    }
107}