Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect data annotations #53

Open
dzmitry-lahoda opened this issue Jan 23, 2022 · 5 comments
Open

respect data annotations #53

dzmitry-lahoda opened this issue Jan 23, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@dzmitry-lahoda
Copy link

dzmitry-lahoda commented Jan 23, 2022

[ValueObject(typeof(int))]
[System.ComponentModel.DataAnnotations.Range(2,100, Error = "Generate validator from this. Hm. Even compile time validator for well know annotations"]
public partial struct CustomerId {
}
@dzmitry-lahoda dzmitry-lahoda changed the title respet data annotations respect data annotations Jan 23, 2022
@Herdo
Copy link
Contributor

Herdo commented Aug 29, 2022

From the existing attributes, these might be relevant (ordered descending by usefulness, IMO):

@dzmitry-lahoda
Copy link
Author

at least one example can be handy to provide patches for others:) Range is good target.

@SteveDunn SteveDunn added the enhancement New feature or request label Oct 22, 2024
@SteveDunn
Copy link
Owner

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! 👍

@dzmitry-lahoda
Copy link
Author

dzmitry-lahoda commented Oct 24, 2024

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.

@SteveDunn
Copy link
Owner

Thanks, I'll take a look around some of these!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants