SerializedValueExpression.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright 2016-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.Bson.Serialization;
  18. using MongoDB.Driver.Core.Misc;
  19. namespace MongoDB.Driver.Linq.Expressions
  20. {
  21. internal sealed class SerializedConstantExpression : SerializationExpression
  22. {
  23. private readonly object _value;
  24. private readonly IBsonSerializer _serializer;
  25. public SerializedConstantExpression(object value, IBsonSerializer serializer)
  26. {
  27. _value = Ensure.IsNotNull(value, nameof(value));
  28. _serializer = Ensure.IsNotNull(serializer, nameof(serializer));
  29. }
  30. public override ExtensionExpressionType ExtensionType
  31. {
  32. get { return ExtensionExpressionType.SerializedConstant; }
  33. }
  34. public override IBsonSerializer Serializer
  35. {
  36. get { return _serializer; }
  37. }
  38. public override Type Type
  39. {
  40. get { return _serializer.ValueType; }
  41. }
  42. public object Value
  43. {
  44. get { return _value; }
  45. }
  46. public override string ToString()
  47. {
  48. return $"Constant({_value.ToString()})";
  49. }
  50. protected internal override Expression Accept(ExtensionExpressionVisitor visitor)
  51. {
  52. return visitor.VisitSerializedConstant(this);
  53. }
  54. }
  55. }