Files
Shrlalgo.RvKits/ShrlAlgoToolkit.Mvvm/Attributes/NotNullOrEmptyAttribute.cs

14 lines
540 B
C#
Raw Normal View History

2024-09-22 11:05:41 +08:00
using System.ComponentModel.DataAnnotations;
2025-04-24 20:56:44 +08:00
namespace ShrlAlgoToolkit.Mvvm.Attributes;
2024-09-22 11:05:41 +08:00
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class NotNullOrEmptyAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var b = value != null || (value is string str && !string.IsNullOrEmpty(str));
return b ? ValidationResult.Success : new("输入内容不是数值。");
}
}