howto use C# record type as criteria #3456
Replies: 1 comment
-
I'm not entirely sure how to make this happen, but I haven't researched it either. The It also knows how to serialize "primitive" types. I put that in quotes, because in this context "primitive" includes some complex types like string, Guid, etc. We might be able to use reflection to serialize record types. That'd be slower, but might work? There's been some discussion of having a type that serializes other types, probably based on an attribute, or maybe some registration dictionary. The idea being that any arbitrary type could be serialized by invoking a serializer for that type. That extension concept would enable someone to write a serializer for a record type (for example) that uses whatever scheme someone would choose. As to why a shallow serializer like JsonSerializer or many similar options won't work, it is because they don't serialize private fields, and when deserializing, they don't preserve the original object graph shape. They always create extra objects in the resulting object graph. CSLA requires a full fidelity serialization scheme where the output of deserialization is exactly the same as the input graph. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all,
I'd like to use C# record type as criteria.
From what I understood, CriteriaBase should no longer be used (I found a disucssion where it got called obsolete).
A regular class has a lot of code to write for no value, where a record fits in just one line. Plus the fact that records are immutable, which supports the criteria idea from my point.
My problem is that I cannot derive a record from a class, so I cannot derive from MobileObject.
Next I tried was to implement IMobileObject into a record directly. Looked promising in the first place, but still does not serialize.
Then I tried to write my own MobileFormatter, but also this did not succeed because IMobileObject is using the explicit type "MobileFormatter" in its SetChildren / GetChildren methods.
So, what else can I do to use a C#9 record with CSLA (as criteria)?
Any idea welcome,
Thanks, Sebastian
Side questions:
Beta Was this translation helpful? Give feedback.
All reactions