2025-02-10 20:53:40 +08:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.Mvvm.Attributes;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
|
|
|
|
|
|
public sealed class MinimumAttribute : ValidationAttribute
|
|
|
|
|
|
{
|
|
|
|
|
|
public MinimumAttribute(double minValue = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
MinValue = minValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public double MinValue { get; }
|
|
|
|
|
|
|
|
|
|
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
|
|
|
|
{
|
2025-07-11 09:20:23 +08:00
|
|
|
|
return double.TryParse(value.ToString(), out var d) && d >= MinValue ? ValidationResult.Success : new ValidationResult($"最小值应为{MinValue}");
|
2024-09-22 11:05:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|