|
14 | 14 | */
|
15 | 15 |
|
16 | 16 | using MongoDB.Bson;
|
17 |
| -using MongoDB.Driver.Core.Misc; |
| 17 | +using MongoDB.Bson.Serialization; |
| 18 | +using MongoDB.Bson.Serialization.Attributes; |
18 | 19 |
|
19 | 20 | namespace MongoDB.Driver
|
20 | 21 | {
|
21 | 22 | /// <summary>
|
22 | 23 | /// An output document from a $changeStream pipeline stage.
|
23 | 24 | /// </summary>
|
24 | 25 | /// <typeparam name="TDocument">The type of the document.</typeparam>
|
25 |
| - public sealed class ChangeStreamDocument<TDocument> |
| 26 | + [BsonSerializer(typeof(ChangeStreamDocumentSerializer<>))] |
| 27 | + public sealed class ChangeStreamDocument<TDocument> : BsonDocumentBackedClass |
26 | 28 | {
|
27 |
| - // private fields |
28 |
| - private readonly CollectionNamespace _collectionNamespace; |
29 |
| - private readonly BsonDocument _documentKey; |
30 |
| - private readonly TDocument _fullDocument; |
31 |
| - private readonly ChangeStreamOperationType _operationType; |
32 |
| - private readonly BsonDocument _resumeToken; |
33 |
| - private readonly ChangeStreamUpdateDescription _updateDescription; |
34 |
| - |
35 | 29 | // constructors
|
36 | 30 | /// <summary>
|
37 |
| - /// Initializes a new instance of the <see cref="ChangeStreamDocument{TDocument}" /> class. |
| 31 | + /// Initializes a new instance of the <see cref="ChangeStreamDocument{TDocument}"/> class. |
38 | 32 | /// </summary>
|
39 |
| - /// <param name="resumeToken">The resume token.</param> |
40 |
| - /// <param name="operationType">Type of the operation.</param> |
41 |
| - /// <param name="collectionNamespace">Namespace of the collection.</param> |
42 |
| - /// <param name="documentKey">The document key.</param> |
43 |
| - /// <param name="updateDescription">The update description.</param> |
44 |
| - /// <param name="fullDocument">The full document.</param> |
| 33 | + /// <param name="backingDocument">The backing document.</param> |
| 34 | + /// <param name="documentSerializer">The document serializer.</param> |
45 | 35 | public ChangeStreamDocument(
|
46 |
| - BsonDocument resumeToken, |
47 |
| - ChangeStreamOperationType operationType, |
48 |
| - CollectionNamespace collectionNamespace, |
49 |
| - BsonDocument documentKey, |
50 |
| - ChangeStreamUpdateDescription updateDescription, |
51 |
| - TDocument fullDocument) |
| 36 | + BsonDocument backingDocument, |
| 37 | + IBsonSerializer<TDocument> documentSerializer) |
| 38 | + : base(backingDocument, new ChangeStreamDocumentSerializer<TDocument>(documentSerializer)) |
52 | 39 | {
|
53 |
| - _resumeToken = Ensure.IsNotNull(resumeToken, nameof(resumeToken)); |
54 |
| - _operationType = operationType; |
55 |
| - _collectionNamespace = collectionNamespace; // can be null when operationType is Invalidate |
56 |
| - _documentKey = documentKey; // can be null |
57 |
| - _updateDescription = updateDescription; // can be null |
58 |
| - _fullDocument = fullDocument; // can be null |
59 | 40 | }
|
60 | 41 |
|
61 | 42 | // public properties
|
| 43 | + /// <summary> |
| 44 | + /// Gets the backing document. |
| 45 | + /// </summary> |
| 46 | + new public BsonDocument BackingDocument => base.BackingDocument; |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Gets the cluster time. |
| 50 | + /// </summary> |
| 51 | + /// <value> |
| 52 | + /// The cluster time. |
| 53 | + /// </value> |
| 54 | + public BsonDocument ClusterTime => GetValue<BsonDocument>(nameof(ClusterTime), null); |
| 55 | + |
62 | 56 | /// <summary>
|
63 | 57 | /// Gets the namespace of the collection.
|
64 | 58 | /// </summary>
|
65 | 59 | /// <value>
|
66 | 60 | /// The namespace of the collection.
|
67 | 61 | /// </value>
|
68 |
| - public CollectionNamespace CollectionNamespace => _collectionNamespace; |
| 62 | + public CollectionNamespace CollectionNamespace => GetValue<CollectionNamespace>(nameof(CollectionNamespace), null); |
69 | 63 |
|
70 | 64 | /// <summary>
|
71 | 65 | /// Gets the document key.
|
72 | 66 | /// </summary>
|
73 | 67 | /// <value>
|
74 | 68 | /// The document key.
|
75 | 69 | /// </value>
|
76 |
| - public BsonDocument DocumentKey => _documentKey; |
| 70 | + public BsonDocument DocumentKey => GetValue<BsonDocument>(nameof(DocumentKey), null); |
77 | 71 |
|
78 | 72 | /// <summary>
|
79 | 73 | /// Gets the full document.
|
80 | 74 | /// </summary>
|
81 | 75 | /// <value>
|
82 | 76 | /// The full document.
|
83 | 77 | /// </value>
|
84 |
| - public TDocument FullDocument => _fullDocument; |
| 78 | + public TDocument FullDocument => GetValue<TDocument>(nameof(FullDocument), default(TDocument)); |
85 | 79 |
|
86 | 80 | /// <summary>
|
87 | 81 | /// Gets the type of the operation.
|
88 | 82 | /// </summary>
|
89 | 83 | /// <value>
|
90 | 84 | /// The type of the operation.
|
91 | 85 | /// </value>
|
92 |
| - public ChangeStreamOperationType OperationType => _operationType; |
| 86 | + public ChangeStreamOperationType OperationType => GetValue<ChangeStreamOperationType>(nameof(OperationType), (ChangeStreamOperationType)(-1)); |
93 | 87 |
|
94 | 88 | /// <summary>
|
95 | 89 | /// Gets the resume token.
|
96 | 90 | /// </summary>
|
97 | 91 | /// <value>
|
98 | 92 | /// The resume token.
|
99 | 93 | /// </value>
|
100 |
| - public BsonDocument ResumeToken => _resumeToken; |
| 94 | + public BsonDocument ResumeToken => GetValue<BsonDocument>(nameof(ResumeToken), null); |
101 | 95 |
|
102 | 96 | /// <summary>
|
103 | 97 | /// Gets the update description.
|
104 | 98 | /// </summary>
|
105 | 99 | /// <value>
|
106 | 100 | /// The update description.
|
107 | 101 | /// </value>
|
108 |
| - public ChangeStreamUpdateDescription UpdateDescription => _updateDescription; |
| 102 | + public ChangeStreamUpdateDescription UpdateDescription => GetValue<ChangeStreamUpdateDescription>(nameof(UpdateDescription), null); |
109 | 103 | }
|
110 | 104 | }
|
0 commit comments