IBsonSerializable.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Copyright 2010-2014 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 MongoDB.Bson.IO;
  17. namespace MongoDB.Bson.Serialization
  18. {
  19. /// <summary>
  20. /// An interface implemented by classes that handle their own BSON serialization.
  21. /// </summary>
  22. public interface IBsonSerializable
  23. {
  24. /// <summary>
  25. /// Deserializes this object from a BsonReader.
  26. /// </summary>
  27. /// <param name="bsonReader">The BsonReader.</param>
  28. /// <param name="nominalType">The nominal type of the object.</param>
  29. /// <param name="options">The serialization options.</param>
  30. /// <returns>Normally itself, though sometimes an instance of a subclass or null.</returns>
  31. object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options);
  32. /// <summary>
  33. /// Gets the document Id.
  34. /// </summary>
  35. /// <param name="id">The Id.</param>
  36. /// <param name="idNominalType">The nominal type of the Id.</param>
  37. /// <param name="idGenerator">The IdGenerator for the Id type.</param>
  38. /// <returns>True if the document has an Id.</returns>
  39. bool GetDocumentId(out object id, out Type idNominalType, out IIdGenerator idGenerator);
  40. /// <summary>
  41. /// Serializes this object to a BsonWriter.
  42. /// </summary>
  43. /// <param name="bsonWriter">The BsonWriter.</param>
  44. /// <param name="nominalType">The nominal type of this object.</param>
  45. /// <param name="options">The serialization options.</param>
  46. void Serialize(BsonWriter bsonWriter, Type nominalType, IBsonSerializationOptions options);
  47. /// <summary>
  48. /// Sets the document Id.
  49. /// </summary>
  50. /// <param name="id">The Id.</param>
  51. void SetDocumentId(object id);
  52. }
  53. }