c#获取特性DescriptionAttribute的值
int detailId = Convert.ToInt32(id); BillLoanApplyDetail model = _billLoadApplyDetail.GetBillLoanApplyDetailById(detailId); Dictionary<string, string> dictList = new Dictionary<string, string>(); if (model != null) { PropertyInfo[] ps = model.GetType().GetProperties(); foreach (PropertyInfo info in ps) { if (info.Name.ToLower() != "id") { string descriptionName = ((DescriptionAttribute)Attribute.GetCustomAttribute(info, typeof(DescriptionAttribute))).Description;// 属性值 var infoValue = info.GetValue(model); dictList.Add(descriptionName, infoValue!=null?info.GetValue(model).ToString():string.Empty); } } return Json(dictList, JsonRequestBehavior.AllowGet); } else { return Json("没有详情",JsonRequestBehavior.AllowGet); }
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70753.html