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