Skip to content

use the parameter's runtime type to resolve the validator rather than its declared type#47

Merged
mvdgun merged 3 commits intoSharpGrip:masterfrom
icnocop:master
Dec 11, 2024
Merged

use the parameter's runtime type to resolve the validator rather than its declared type#47
mvdgun merged 3 commits intoSharpGrip:masterfrom
icnocop:master

Conversation

@icnocop
Copy link
Contributor

@icnocop icnocop commented Dec 10, 2024

Fixes #46

{
var parameterInfo = (parameter as ControllerParameterDescriptor)?.ParameterInfo;
var parameterType = parameter.ParameterType;
var parameterType = subject!.GetType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know for sure that subject is not null if the TryGetValue returns true in this case? Further down there is a null check on subject.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed another commit to support a potentially nullable subject.

Thank you.

if (subject != null && parameterType.IsCustomType() &&
!hasAutoValidateNeverAttribute && (hasAutoValidateAlwaysAttribute || HasValidBindingSource(bindingSource)) &&
serviceProvider.GetValidator(parameterType) is IValidator validator)
serviceProvider.GetValidator(parameterType!) is IValidator validator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@icnocop now you are overriding the nullability over here, I would do:

subject != null && parameterType != null && parameterType.IsCustomType() && etc...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure when parameterType would be null when subject is not null.

In any case, I just pushed another commit to support a potentially nullable parameterType, as you recommended.

Thank you.

@mvdgun mvdgun merged commit eb7fd03 into SharpGrip:master Dec 11, 2024
@mvdgun
Copy link
Member

mvdgun commented Dec 11, 2024

Merged, thank you!

@mvdgun mvdgun changed the title Use the method parameter's runtime (instance) type to find the validator instead of its declared type use the parameter's runtime type to resolve the validator rather than its declared type Dec 18, 2024
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

Successfully merging this pull request may close these issues.

Use the method parameter's runtime (instance) type to find the validator instead of its declared type

2 participants