Open dzmitry-lahoda opened 2 years ago
From the existing attributes, these might be relevant (ordered descending by usefulness, IMO):
at least one example can be handy to provide patches for others:) Range is good target.
Thanks for the suggestion @dzmitry-lahoda . Perhaps this would be better as a field, which would allow fluent chaining to combine validators. Vogen could then recognise and parse those fields and generate the appropriate validation rules from them. I particularly like your idea of using well known validators at compile time! 👍
Hello, than you for continue to improve C#, so I moved to Rust.
What I found so, Rust attribute proc macro is very close to C# source generators.
I feel that you may find very solid designs in Rust crates for many things C# capable of.
In Rust, unfortunately, there is no generic standard validation attributes. Each crate clap/serde/prost do their own validations. So serde seems mostly shared (schemars uses serde). May be some of these design can be good to look at.
May be not exactly relevant, but C# can also be extended with idiomatic partial application and type state builders like this thing does https://github.com/elastio/bon .
So I believe if anything in C# existing validation attributes prevents some forms of being statically typed or some other limitation, it should be avoid and some specialization used (for example JSON validation composable with Vogen is interesting) or builder like validation (via type state). Because there is some well known success doing so in similar language.
Thanks, I'll take a look around some of these!