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); } } }