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

[Question] Dependent - Attribute Based Validations? #143

Closed
Simonl9l opened this issue Sep 4, 2024 · 2 comments
Closed

[Question] Dependent - Attribute Based Validations? #143

Simonl9l opened this issue Sep 4, 2024 · 2 comments

Comments

@Simonl9l
Copy link

Simonl9l commented Sep 4, 2024

Per the Readme section on this, is there a way to create a custom validation that can validate based on the value of another option/argument?

Is there an example, or could the documentation be updated to demonstrate this?

There is potential and example here that validates across properties of a class, but given that this Framework does not use class for the Options/Arguments but method parameters, I'm not sure how this can work.

@neuecc
Copy link
Member

neuecc commented Sep 9, 2024

If you implement ValidationAttribute, it will work without any issues.
This is not specific to this framework, but a general approach, so please research it on your own.

@neuecc neuecc closed this as completed Sep 9, 2024
@Simonl9l
Copy link
Author

Simonl9l commented Sep 14, 2024

Whilst outside of the scope on Asp.Net Core once can use the ValidationAttribute as soon as you want to do things like access other dependent arguments, and services from the DI container to complete validations, all bets seem to be off.

Also the ValidationContext that is needed (it seems) to support this is littered with [RequiresUnreferencedCode] attributes that make it non AOT-able.

I guess I'll just do validation inside the command, for now, but do note that both .Net Core and C# have threads on providing code generation support for parameter validations:
dotnet/aspnetcore#46349
dotnet/csharplang#6373

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

No branches or pull requests

2 participants