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