DefaultIfEmptyExpression.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 DefaultIfEmptyExpression : ExtensionExpression, ISourcedExpression
  21. {
  22. private readonly Expression _source;
  23. public DefaultIfEmptyExpression(Expression source)
  24. {
  25. _source = Ensure.IsNotNull(source, nameof(source));
  26. }
  27. public override ExtensionExpressionType ExtensionType
  28. {
  29. get { return ExtensionExpressionType.DefaultIfEmpty; }
  30. }
  31. public Expression Source
  32. {
  33. get { return _source; }
  34. }
  35. public override Type Type
  36. {
  37. get { return _source.Type; }
  38. }
  39. public override string ToString()
  40. {
  41. return string.Format("{0}.DefaultIfEmpty()", _source.ToString());
  42. }
  43. public DefaultIfEmptyExpression Update(Expression source)
  44. {
  45. if (source != _source)
  46. {
  47. return new DefaultIfEmptyExpression(source);
  48. }
  49. return this;
  50. }
  51. protected internal override Expression Accept(ExtensionExpressionVisitor visitor)
  52. {
  53. return visitor.VisitDefaultIfEmpty(this);
  54. }
  55. }
  56. }