BsonDocumentWrapperSerializer.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright 2010-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. namespace MongoDB.Bson.Serialization.Serializers
  16. {
  17. /// <summary>
  18. /// Represents a serializer for BsonDocumentWrappers.
  19. /// </summary>
  20. public class BsonDocumentWrapperSerializer : BsonValueSerializerBase<BsonDocumentWrapper>
  21. {
  22. // private static fields
  23. private static BsonDocumentWrapperSerializer __instance = new BsonDocumentWrapperSerializer();
  24. // constructors
  25. /// <summary>
  26. /// Initializes a new instance of the BsonDocumentWrapperSerializer class.
  27. /// </summary>
  28. public BsonDocumentWrapperSerializer()
  29. : base(BsonType.Document)
  30. {
  31. }
  32. // public static properties
  33. /// <summary>
  34. /// Gets an instance of the BsonDocumentWrapperSerializer class.
  35. /// </summary>
  36. public static BsonDocumentWrapperSerializer Instance
  37. {
  38. get { return __instance; }
  39. }
  40. // public methods
  41. /// <summary>
  42. /// Deserializes a class.
  43. /// </summary>
  44. /// <param name="context">The deserialization context.</param>
  45. /// <param name="args">The deserialization args.</param>
  46. /// <returns>A deserialized value.</returns>
  47. public override BsonDocumentWrapper Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
  48. {
  49. throw CreateCannotBeDeserializedException();
  50. }
  51. // protected methods
  52. /// <summary>
  53. /// Deserializes a class.
  54. /// </summary>
  55. /// <param name="context">The deserialization context.</param>
  56. /// <param name="args">The deserialization args.</param>
  57. /// <returns>An object.</returns>
  58. protected override BsonDocumentWrapper DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
  59. {
  60. throw CreateCannotBeDeserializedException();
  61. }
  62. /// <summary>
  63. /// Serializes a value.
  64. /// </summary>
  65. /// <param name="context">The serialization context.</param>
  66. /// <param name="args">The serialization args.</param>
  67. /// <param name="value">The object.</param>
  68. protected override void SerializeValue(BsonSerializationContext context, BsonSerializationArgs args, BsonDocumentWrapper value)
  69. {
  70. value.Serializer.Serialize(context, value.Wrapped);
  71. }
  72. }
  73. }