SkipExpression.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * skipations under the License.
  14. */
  15. using System;
  16. using System.Linq.Expressions;
  17. using MongoDB.Driver.Core.Misc;
  18. namespace MongoDB.Driver.Linq.Expressions
  19. {
  20. internal sealed class SkipExpression : ExtensionExpression, ISourcedExpression
  21. {
  22. private readonly Expression _count;
  23. private readonly Expression _source;
  24. public SkipExpression(Expression source, Expression count)
  25. {
  26. _source = Ensure.IsNotNull(source, nameof(source));
  27. _count = Ensure.IsNotNull(count, nameof(count));
  28. }
  29. public override ExtensionExpressionType ExtensionType
  30. {
  31. get { return ExtensionExpressionType.Skip; }
  32. }
  33. public Expression Count
  34. {
  35. get { return _count; }
  36. }
  37. public Expression Source
  38. {
  39. get { return _source; }
  40. }
  41. public override Type Type
  42. {
  43. get { return _source.Type; }
  44. }
  45. public override string ToString()
  46. {
  47. return string.Format("{0}.Skip({1})", _source.ToString(), _count.ToString());
  48. }
  49. public SkipExpression Update(Expression source, Expression count)
  50. {
  51. if (source != _source ||
  52. count != _count)
  53. {
  54. return new SkipExpression(source, count);
  55. }
  56. return this;
  57. }
  58. protected internal override Expression Accept(ExtensionExpressionVisitor visitor)
  59. {
  60. return visitor.VisitSkip(this);
  61. }
  62. }
  63. }