DistinctExpression.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. using MongoDB.Driver.Core.Misc;
  17. namespace MongoDB.Driver.Linq.Expressions
  18. {
  19. internal sealed class DistinctExpression : ExtensionExpression, ISourcedExpression
  20. {
  21. private readonly Expression _source;
  22. public DistinctExpression(Expression source)
  23. {
  24. _source = Ensure.IsNotNull(source, nameof(source));
  25. }
  26. public Expression Source
  27. {
  28. get { return _source; }
  29. }
  30. public override ExtensionExpressionType ExtensionType
  31. {
  32. get { return ExtensionExpressionType.Distinct; }
  33. }
  34. public override string ToString()
  35. {
  36. return string.Format("{0}.Distinct()", _source.ToString());
  37. }
  38. public DistinctExpression Update(Expression source)
  39. {
  40. if (source != _source)
  41. {
  42. return new DistinctExpression(source);
  43. }
  44. return this;
  45. }
  46. protected internal override Expression Accept(ExtensionExpressionVisitor visitor)
  47. {
  48. return visitor.VisitDistinct(this);
  49. }
  50. }
  51. }