环境:net framework 4.5.2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DrwmePMS.Model {
public class ReportProgress {
[Description("项目名称")]
public string ProjectName { get; set; }
[Description("需求内容")]
public string NeedTitle { get; set; }
[Description("当前状态")]
public string NeedsStage { get; set; }
[Description("人员")]
public string Person { get; set; }
[Description("计划日期")]
public DateTime? DatePlan { get; set; }
[Description("实际交付日期")]
public DateTime? DateComplete { get; set; }
[Description("逾期天数")]
public int? OverdueDay { get; set; }
[Description("交付次数")]
public int? Count { get; set; }
}
}
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;
}
}