Closed dzmitry-lahoda closed 10 months ago
I'm not entirely sure if that's possible in this library. We could not scaffold the constructor, which would allow you to create your own, but if I remember correctly you can't enforce that a non-default constructor is called in structs. A better option is probably to use a factory function to guard creation, and create your own JSON converters to check for constraints I guess
another example - id of guest account is 0. non guest is > 0. I want id which is 1+.
I understand the desire, it just does not seem feasible currently with structs. Plus I see this library become pretty much obsolete with C#9
The only option I see in the short term is to support class
as well as struct
, and allow making the constructor private, so that you can write your own public constructor (while still allowing to create from JSON, if they type convert options are enabled)
pretty much obsolete with C#9
with public data class Person
? it is class (GC) with no automatic operators to cast to and from to internal state (for id it is single value). Also StronglyTypedId
may generate records in future.
Hi @dzmitry-lahoda - I have something similar to @andrewlock 's library, called Vogen. It's similar, but different insofar as it's more focused on 'Value Objects', in particular validation. It has analyzers that break the build if certain situations arise where validation could be bypassed
Allow to limit string to 50 chars and ushort to 14 bits. I want to use this in games.