using System.ComponentModel.DataAnnotations; namespace ShrlAlgo.Toolkit.Mvvm.Attributes; [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)] public sealed class IsNumericAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { return double.TryParse(value.ToString(), out var _) ? ValidationResult.Success : new("输入内容不是数值。"); } }