using System;
using System.ComponentModel.DataAnnotations;
namespace Masuit.Tools.Core.Validator;
///
/// 最大值校验
///
public class MaxValueAttribute : ValidationAttribute
{
private double MaxValue { get; }
///
/// 最大值
///
///
public MaxValueAttribute(double value)
{
MaxValue = value;
}
///
/// 最大值校验
///
///
///
public override bool IsValid(object value)
{
if (value is null)
{
return true;
}
var input = Convert.ToDouble(value);
return input <= MaxValue;
}
/// Applies formatting to an error message, based on the data field where the error occurred.
/// The name to include in the formatted message.
/// An instance of the formatted error message.
public override string FormatErrorMessage(string name)
{
return base.FormatErrorMessage(name);
}
}