20 lines
656 B
C#
20 lines
656 B
C#
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.Common.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($"输入值超出范围,最大值应为{MaxValue}");
|
|
}
|
|
}
|