public class BillReceiveModelDTO { /// <summary> /// /// </summary> [DataMember] [Required(ErrorMessage = "非空")] public string orderNo { set; get; } } //验证private static IEnumerable<string> VerifyTelegram(BillReceiveModelDTO telegram) { foreach (var property in typeof(BillReceiveModelDTO).GetProperties()) { var attr = property.GetAttributes<RequiredAttribute>(false).FirstOrDefault(); if (attr != null && !attr.IsValid(property.GetValue(telegram, null))) yield return attr.ErrorMessage; } }
时间: 2024-10-03 13:38:46