添加项目文件。
This commit is contained in:
19
Sai.Toolkit.Mvvm/Attributes/MaximumAttribute.cs
Normal file
19
Sai.Toolkit.Mvvm/Attributes/MaximumAttribute.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Sai.Toolkit.Mvvm.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
|
||||
public sealed class MaximumAttribute : ValidationAttribute
|
||||
{
|
||||
public MaximumAttribute(double maxValue = 0)
|
||||
{
|
||||
MaxValue = maxValue;
|
||||
}
|
||||
|
||||
public double MaxValue { get; }
|
||||
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
return double.TryParse(value.ToString(), out var d) && d <= MaxValue ? ValidationResult.Success : new ValidationResult("输入值超出范围");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user