2024-09-22 11:05:41 +08:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
2026-02-21 16:31:24 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.Common.Attributes;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
[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)
|
|
|
|
|
|
{
|
2025-07-11 09:20:23 +08:00
|
|
|
|
return double.TryParse(value.ToString(), out var d) && d <= MaxValue ? ValidationResult.Success : new ValidationResult($"输入值超出范围,最大值应为{MaxValue}");
|
2024-09-22 11:05:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|