CollectionExpression.cs 2.1 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. * limitations under the License.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq.Expressions;
  18. using MongoDB.Bson.Serialization;
  19. using MongoDB.Bson.Serialization.Serializers;
  20. using MongoDB.Driver.Core.Misc;
  21. namespace MongoDB.Driver.Linq.Expressions
  22. {
  23. internal sealed class CollectionExpression : SerializationExpression
  24. {
  25. private readonly CollectionNamespace _collectionNamespace;
  26. private readonly IBsonSerializer _serializer;
  27. public CollectionExpression(CollectionNamespace collectionNamespace, IBsonSerializer itemSerializer)
  28. {
  29. _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace));
  30. _serializer = SerializerHelper.CreateEnumerableSerializer(Ensure.IsNotNull(itemSerializer, nameof(itemSerializer)));
  31. }
  32. public override ExtensionExpressionType ExtensionType
  33. {
  34. get { return ExtensionExpressionType.Collection; }
  35. }
  36. public CollectionNamespace CollectionNamespace
  37. {
  38. get { return _collectionNamespace; }
  39. }
  40. public override IBsonSerializer Serializer
  41. {
  42. get { return _serializer; }
  43. }
  44. public override Type Type
  45. {
  46. get { return _serializer.ValueType; }
  47. }
  48. public override string ToString()
  49. {
  50. return $"[{_collectionNamespace}]";
  51. }
  52. protected internal override Expression Accept(ExtensionExpressionVisitor visitor)
  53. {
  54. return visitor.VisitCollection(this);
  55. }
  56. }
  57. }