Add support for ValueTypes that consist only of Fields #2571
Fixes https://github.com/litedb-org/LiteDB/issues/2570 Also fixes issues in https://github.com/litedb-org/LiteDB/pull/2568
@Joy-less One last opinion pretty please? :)
From what I can tell, this is just because BsonMapper sets IncludeFields to false by default. So the behaviour is functioning correctly. It would make more sense imo to set IncludeFields to true by default or to put a warning that ValueTuple uses fields not properties.
Hi Joy-Less,
Thank you for your feedback! The goal of this PR is to make serialization more intuitive while preserving current defaults. Classes typically rely on properties to define their data, so the default behavior (IncludeFields = false) makes sense to avoid unintentionally serializing fields. Structs, on the other hand, often use fields for their data, and this change ensures field-only structs like ValueTuple are handled correctly. For structs with properties, the logic still respects properties as the primary data source.
I also have the feeling that the library was developed with classes in mind and didn’t fully consider how structs might be used. This PR addresses that gap by improving support for structs while maintaining compatibility with the original design philosophy.
Changing IncludeFields to true by default could break existing applications, so this PR carefully enhances support for specific cases like field-only value types without altering established behavior. I believe this strikes a good balance between stability and usability.
Looking forward to your thoughts!
I understand. Please write a comment in the source code clearly explaining this reasoning, then I will approve.