using HKElectric.ESafety.Utilities; using System.ComponentModel.DataAnnotations; namespace HKElectric.ESafety.WebAPI { public class StringByteLengthAttribute : ValidationAttribute { public int MaximumLength { get; set; } public StringByteLengthAttribute(int maximumLength) { MaximumLength = maximumLength; } public override string FormatErrorMessage(string name) { return string.Format(CustomeMessage.SAFETYDOCUMENT_BYTE_VERIFY, name, MaximumLength); } public override bool IsValid(object? value) { string? context = value != null ? value.ToString() : string.Empty; return !string.IsNullOrWhiteSpace(context) ? StringUtil.CountByteLength(context, MaximumLength) : true; } } }
标签:string,自定义,value,MaximumLength,context,StringByteLength,public From: https://www.cnblogs.com/tx1185498724/p/16902505.html