GridFSFileInfoSerializerCompat.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 MongoDB.Bson;
  16. using MongoDB.Bson.Serialization;
  17. using MongoDB.Bson.Serialization.Serializers;
  18. namespace MongoDB.Driver.GridFS
  19. {
  20. /// <summary>
  21. /// Represents a serializer for GridFSFileInfo.
  22. /// </summary>
  23. public class GridFSFileInfoSerializer : BsonDocumentBackedClassSerializer<GridFSFileInfo>
  24. {
  25. private static readonly GridFSFileInfoSerializer __instance = new GridFSFileInfoSerializer();
  26. /// <summary>
  27. /// Gets the pre-created instance.
  28. /// </summary>
  29. public static GridFSFileInfoSerializer Instance
  30. {
  31. get { return __instance; }
  32. }
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="GridFSFileInfoSerializer" /> class.
  35. /// </summary>
  36. public GridFSFileInfoSerializer()
  37. {
  38. RegisterMember("Aliases", "aliases", new ArraySerializer<string>());
  39. RegisterMember("ChunkSizeBytes", "chunkSize", new Int32Serializer());
  40. RegisterMember("ContentType", "contentType", new StringSerializer());
  41. RegisterMember("Filename", "filename", new StringSerializer());
  42. RegisterMember("IdAsBsonValue", "_id", BsonValueSerializer.Instance);
  43. RegisterMember("Length", "length", new Int64Serializer());
  44. RegisterMember("MD5", "md5", new StringSerializer());
  45. RegisterMember("Metadata", "metadata", BsonDocumentSerializer.Instance);
  46. RegisterMember("UploadDateTime", "uploadDate", new DateTimeSerializer());
  47. }
  48. /// <inheritdoc/>
  49. protected override GridFSFileInfo CreateInstance(BsonDocument backingDocument)
  50. {
  51. return new GridFSFileInfo(backingDocument);
  52. }
  53. }
  54. }