OrderByClause.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright 2015-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System.Linq.Expressions;
  16. namespace MongoDB.Driver.Linq.Expressions
  17. {
  18. internal sealed class OrderByClause
  19. {
  20. private readonly SortDirection _direction;
  21. private readonly Expression _expression;
  22. public OrderByClause(Expression expression, SortDirection direction)
  23. {
  24. _expression = expression;
  25. _direction = direction;
  26. }
  27. public SortDirection Direction
  28. {
  29. get { return _direction; }
  30. }
  31. public Expression Expression
  32. {
  33. get { return _expression; }
  34. }
  35. public override string ToString()
  36. {
  37. return _expression.ToString() + " " + _direction.ToString();
  38. }
  39. public OrderByClause Update(Expression expression)
  40. {
  41. if (expression != _expression)
  42. {
  43. return new OrderByClause(expression, _direction);
  44. }
  45. return this;
  46. }
  47. }
  48. }