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
                        });
                    }
                }
原文地址:https://www.cnblogs.com/xuguanghui/p/5653506.html