码迷,mamicode.com
首页 > Windows程序 > 详细

c#获取特性DescriptionAttribute的值

时间:2015-06-18 12:56:13      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

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

技术分享

c#获取特性DescriptionAttribute的值

标签:

原文地址:http://www.cnblogs.com/honghong75042/p/4585418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!