1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace DrwmePMS.Model {
  8. public class ReportProgress {
  9. [Description("项目名称")]
  10. public string ProjectName { get; set; }
  11. [Description("需求内容")]
  12. public string NeedTitle { get; set; }
  13. [Description("当前状态")]
  14. public string NeedsStage { get; set; }
  15. [Description("人员")]
  16. public string Person { get; set; }
  17. [Description("计划日期")]
  18. public DateTime? DatePlan { get; set; }
  19. [Description("实际交付日期")]
  20. public DateTime? DateComplete { get; set; }
  21. [Description("逾期天数")]
  22. public int? OverdueDay { get; set; }
  23. [Description("交付次数")]
  24. public int? Count { get; set; }
  25. }
  26. }

使用方式获取

Model.ReportProgress progress = new Model.ReportProgress();
foreach (var item in progress.GetType().GetProperties()) {
    //获得属性指定类型得特征,不写得化返回太多了需要做多余得操作
    var attr = item.GetCustomAttributes(typeof(DescriptionAttribute),false);
    if (attr is DescriptionAttribute[] a) {
        var str1 = a[0].Description;
    }
}

效果图

image.png