Adding a new BSON serialization provider to be able to determine that… #219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Because some requirements in my project, I had to create a base class derived by some domain objects which implement
IDictionary<TKey, TValue>
, but these domain objects are still POCOs and I want them to be serialized using regular BSON class map serializer.When I ran some test I found some issue: my domain object wasn't getting an auto-assigned GUID. After clonning the driver source code, I debugged the code step by step and I found that my domain objects were serialized as collections rather than POCOs, because they inherit a base class which implements
IDictionary<TKey, TValue>
as I mentioned above.Then, I thought, what about a way to configure that certain types must be serialized as class maps to solve my issue?, and I implemented a serialization provider
ForceAsBsonClassMapSerializationProvider
to fix my problem.For example, this new provider may be used as follows:
It can be also registered a concrete type to be forced as a BSON class map:
Or also both:
Because I feel that other developers might encounter the same limitation, I believe that it would be a good point merging this simple serialization provider.
Thank you in advance and I'll look forward for your comments, suggestions...!