Files
SzmediTools/Szmedi.RvKits/Attributes/GreaterThanAttribute.cs
2025-09-16 16:06:41 +08:00

25 lines
767 B
C#

using System;
using System.ComponentModel.DataAnnotations;
namespace Szmedi.RvKits.Attributes
{
public class GreaterThanAttribute : ValidationAttribute
{
public GreaterThanAttribute(string propertyName)
{
PropertyName = propertyName;
}
public string PropertyName { get; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
object
instance = validationContext.ObjectInstance,
otherValue = instance.GetType().GetProperty(PropertyName).GetValue(instance);
return ((IComparable)value).CompareTo(otherValue) > 0 ? ValidationResult.Success : new("当前值小于另一个值");
}
}
}