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

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

 

posted @ 2016-07-08 15:26  直钩钓鱼  阅读(1444)  评论(0编辑  收藏  举报