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