您的位置:首页 > 编程语言 > C#

c#通过反射获取自定义属性

2016-07-08 15:26 501 查看
PropertyInfo[] properties = typeof(BPM_ContractApproval_Purchase).GetProperties();

foreach (var property in properties)
{
string text = Convert.ToString(property.GetValue(entity));

var dingtalkAttribute = property.GetCustomAttribute(typeof(DingTalkFormInfoAttribute)) as DingTalkFormInfoAttribute;

if (dingtalkAttribute != null)
{
var attribute = property.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute;

customeAttribute.Add(new BPM_Attribute_Dto()
{
Label = attribute != null ? attribute.Name : "",
Text = text,
OrderIndex = dingtalkAttribute.Index
});
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: