Open MizMahem opened 3 years ago
Digging into the code I found that giving the constructor a blank string or null causes the Validate
error message to be used. This isn't very intuitive and isn't documented anywhere. And in a nullable context, the errorMessage
parameter in the constructor can't even be null. Perhaps it should be allowed to be null for this purpose, or a constructor not taking an errorMessage should be added?
Looked into it today as I thought it would be a good issue to get me started on Hacktoberfest.
It really seems that there is no problem in making the ErrorMessage
property in the ParameterValidationAttribute.cs
nullable, like @MizMahem mentioned.
The CommandValidator
already checks whether the ErrorMessage
is null or whitespace:
The XmlDocCommand
adds it as a nullable attribute.
There seems to be no test coverage, however. Maybe I could look into that and create a PR with test(s), @patriksvensson?
Issue When using custom validation attributes derived from
ParameterValidationAttribute
, the validation error message provided in the attribute constructor overrides anyValidationResult
error message. Using theValidationResult
messages returned byValidate
is probably preferable because in this context theCommandParameterContext
variable can be used to give more detailed feedback on any errors.Example
Please upvote :+1: this issue if you are interested in it.