IBsonSerializer.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. using System;
  16. namespace MongoDB.Bson.Serialization
  17. {
  18. /// <summary>
  19. /// An interface implemented by a serializer.
  20. /// </summary>
  21. public interface IBsonSerializer
  22. {
  23. // properties
  24. /// <summary>
  25. /// Gets the type of the value.
  26. /// </summary>
  27. /// <value>
  28. /// The type of the value.
  29. /// </value>
  30. Type ValueType { get; }
  31. // methods
  32. /// <summary>
  33. /// Deserializes a value.
  34. /// </summary>
  35. /// <param name="context">The deserialization context.</param>
  36. /// <param name="args">The deserialization args.</param>
  37. /// <returns>A deserialized value.</returns>
  38. object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args);
  39. /// <summary>
  40. /// Serializes a value.
  41. /// </summary>
  42. /// <param name="context">The serialization context.</param>
  43. /// <param name="args">The serialization args.</param>
  44. /// <param name="value">The value.</param>
  45. void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value);
  46. }
  47. /// <summary>
  48. /// An interface implemented by a serializer for values of type TValue.
  49. /// </summary>
  50. /// <typeparam name="TValue">The type that this serializer knows how to serialize.</typeparam>
  51. public interface IBsonSerializer<TValue> : IBsonSerializer
  52. {
  53. /// <summary>
  54. /// Deserializes a value.
  55. /// </summary>
  56. /// <param name="context">The deserialization context.</param>
  57. /// <param name="args">The deserialization args.</param>
  58. /// <returns>A deserialized value.</returns>
  59. new TValue Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args);
  60. /// <summary>
  61. /// Serializes a value.
  62. /// </summary>
  63. /// <param name="context">The serialization context.</param>
  64. /// <param name="args">The serialization args.</param>
  65. /// <param name="value">The value.</param>
  66. void Serialize(BsonSerializationContext context, BsonSerializationArgs args, TValue value);
  67. }
  68. }