1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-09-06 16:53:11 +02:00
Files
Minecraft-Phantom-Panel/Web/Phantom.Web.Components/Utils/FormValidationAttribute.cs
2025-08-21 20:31:21 +02:00

18 lines
688 B
C#

using System.ComponentModel.DataAnnotations;
namespace Phantom.Web.Components.Utils;
public abstract class FormValidationAttribute<TModel, TValue> : ValidationAttribute {
public sealed override bool IsValid(object? value) {
return base.IsValid(value);
}
protected sealed override ValidationResult? IsValid(object? value, ValidationContext validationContext) {
var model = (TModel) validationContext.ObjectInstance;
return value is TValue typedValue && IsValid(model, typedValue) ? ValidationResult.Success : new ValidationResult(null, new[] { FieldName });
}
protected abstract string FieldName { get; }
protected abstract bool IsValid(TModel model, TValue value);
}