ZipExpression.cs 2.2 KB

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