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

 

posted on 2014-10-15 16:32  水月无痕  阅读(2730)  评论(0编辑  收藏  举报