[CSHARP-4310] ISupportInitialize methods not called when class derives from Dictionary Created: 07/Sep/22 Updated: 27/Oct/23 Resolved: 27/Sep/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Unknown |
| Reporter: | Mo B. | Assignee: | James Kovacs |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
| Comments |
| Comment by PM Bot [ 27/Sep/22 ] |
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. |
| Comment by James Kovacs [ 12/Sep/22 ] |
|
Hi, Mo, I wanted to follow up further on Boris' comments. The CollectionsSerializationProvider and related classes are intended to allow you to use custom collection types with your POCOs. They are not intended to be POCOs themselves. Typically a POCO would be a class with properties that is initialized with the BSON data read from MongoDB. If you have additional optional properties, you would mark a property as [BsonExtraElements], which could be a BsonDocument or IDictionary<string, object> and it would contain any fields not mapped to explicit properties. You can always take full control of serialization/deserialization by implementing IBsonSerializer<T> yourself. There are various base classes that implement IBsonSerializer<T> that will handle much of the boilerplate code required. For example, see SerializerBase<T>. If all your classes are essentially a property bag with strongly-typed accessor properties, you could write and register your own serialization provider that instantiates the desired IBsonSerializer<T> instances. We do not recommend structuring your POCOs as strongly-typed property bags due to the casting overhead on every property access. Our recommended approach is to use strongly-typed properties mapped via BsonClassMap<T> or BSON attributes. You can further customize using creator maps, [BsonExtraElements], and similar constructs. Please let us know if you have any additional questions. Sincerely, |
| Comment by Boris Dogadov [ 09/Sep/22 ] |
|
Thanks mywyb2@gmail.com for reporting this behaviour. By default DictionaryInterfaceImplementerSerializer serializer is used for classes implementing IDictionary interface. We will be investigating this behaviour further, please follow this ticket for any updates. |
| Comment by Mo B. [ 07/Sep/22 ] |
|
Forgot to mention that this is in .NET 6. |