DEV Community

loading...

Discussion on: [C #] Some scenarios for deserializing a JSON to a type with read-only properties by "System.Text.Json"

Collapse
sharpninja profile image
The Sharp Ninja

This is not a useful way of thinking. Everything evolves and sometimes introduction of new language features, such as init properties, shines light on the inadequacies of old techniques. In this case, private setters or no setter has been part of C# frim the beginning. Having a constructor to initialize read-inly properties has been common since day one. Auto-properties and object initializers caused a big shift in thinking and it became normal to have no constructors at all. Init setters fixes the obvious issue with that. So now you have code bases with three techniques to create a read-only class and serializers need to handle all of the. The fact that adding two attribures allows all use cases to be covered speaks volumes about the foresight of the team building C# in the 1990s.

Forem Open with the Forem app