Tri-Inspector/Editor.Extras/Validators/ValidateInputValidator.cs

37 lines
1.1 KiB
C#
Raw Normal View History

2022-05-11 12:48:50 -04:00
using TriInspector;
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;
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
{
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;
}
return TriExtensionInitializationResult.Ok;
}
2022-05-07 12:04:09 -04:00
public override TriValidationResult Validate(TriProperty property)
{
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
}
}
}