ConcatExpression.cs 1.9 KB

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