Description
Type of issue
Code doesn't work
Description
There is a contradiction in the description of the called method in the documentation and in the source code: in the source code, for called methods with one or two input parameters, there is always one return type - ValidationResult, while the documentation states that a method with one parameter must return the Boolean type.
Source code (from Git):
/// summary
/// Validation attribute that executes a user-supplied method at runtime, using one of these signatures:
/// public static Method(object value) { ... }
/// public static Method(object value, context) {.. }
/// '''
/// /summary
public sealed class CustomValidationAttribute : ValidationAttribute
[ . . . ]
// Invoke the method. Catch TargetInvocationException merely to unwrap it.
// Callers don't know Reflection is being used and will not typically see
// the real exception
try
{
// 1-parameter form is ValidationResult Method(object value)
// 2-parameter form is ValidationResult Method(object value, ValidationContext context),
var methodParams = _isSingleArgumentMethod
? new object?[] { convertedValue }
: new[] { convertedValue, validationContext };
var result = (ValidationResult?)methodInfo!.Invoke(null, methodParams);
[ . . . ]
// Method must return a ValidationResult or derived class
if (!typeof(ValidationResult).IsAssignableFrom(methodInfo.ReturnType))
{
return SR.Format(SR.CustomValidationAttribute_Method_Must_Return_ValidationResult, Method, ValidatorType.Name);
}
[ . . . ]
// We accept 2 forms:
// 1-parameter form is ValidationResult Method(object value)
// 2-parameter form is ValidationResult Method(object value, ValidationContext context),
_isSingleArgumentMethod = (parameterInfos.Length == 1);
[ . . . ]
Page URL
Content source URL
Document Version Independent Id
ba1cc98b-e6b7-bf0a-9307-d450b7ff2a35