2022-05-11 12:48:50 -04:00
|
|
|
|
using TriInspector;
|
2022-05-09 08:12:30 -04:00
|
|
|
|
using TriInspector.Resolvers;
|
2022-05-07 12:04:09 -04:00
|
|
|
|
using TriInspector.Validators;
|
|
|
|
|
|
2022-05-07 12:30:05 -04:00
|
|
|
|
[assembly: RegisterTriAttributeValidator(typeof(ValidateInputValidator))]
|
2022-05-07 12:04:09 -04:00
|
|
|
|
|
|
|
|
|
namespace TriInspector.Validators
|
|
|
|
|
{
|
|
|
|
|
public class ValidateInputValidator : TriAttributeValidator<ValidateInputAttribute>
|
|
|
|
|
{
|
2022-05-11 12:48:50 -04:00
|
|
|
|
private ValueResolver<TriValidationResult> _resolver;
|
2022-05-09 08:12:30 -04:00
|
|
|
|
|
2022-06-06 07:17:53 -04:00
|
|
|
|
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
|
2022-05-09 08:12:30 -04:00
|
|
|
|
{
|
|
|
|
|
base.Initialize(propertyDefinition);
|
|
|
|
|
|
2022-05-11 12:48:50 -04:00
|
|
|
|
_resolver = ValueResolver.Resolve<TriValidationResult>(propertyDefinition, Attribute.Method);
|
2022-06-03 08:16:23 -04:00
|
|
|
|
|
|
|
|
|
if (_resolver.TryGetErrorString(out var error))
|
|
|
|
|
{
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 07:17:53 -04:00
|
|
|
|
return TriExtensionInitializationResult.Ok;
|
2022-05-09 08:12:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-07 12:04:09 -04:00
|
|
|
|
public override TriValidationResult Validate(TriProperty property)
|
|
|
|
|
{
|
2022-05-09 08:12:30 -04:00
|
|
|
|
if (_resolver.TryGetErrorString(out var error))
|
|
|
|
|
{
|
|
|
|
|
return TriValidationResult.Error(error);
|
|
|
|
|
}
|
2022-05-07 12:04:09 -04:00
|
|
|
|
|
2022-05-11 12:48:50 -04:00
|
|
|
|
return _resolver.GetValue(property);
|
2022-05-07 12:04:09 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|