LiteDB icon indicating copy to clipboard operation
LiteDB copied to clipboard

Add support for ValueTypes that consist only of Fields #2571

Open JKamsker opened this issue 1 year ago • 3 comments

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? :)

JKamsker avatar Dec 02 '24 08:12 JKamsker

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.

Joy-less avatar Dec 02 '24 13:12 Joy-less

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!

JKamsker avatar Dec 03 '24 01:12 JKamsker

I understand. Please write a comment in the source code clearly explaining this reasoning, then I will approve.

Joy-less avatar Dec 03 '24 01:12 Joy-less