LiXiang98

导航

 
var shipmentColumnNames = new List<string>();
var shipmentColumnNames = new List<string>();
var shipmentPropNames = new List<string>();
var props = typeof(TestClass).GetProperties().ToList(); props.ForEach((p)
=> { if (p.IsDefined(typeof(ExcelColumnNameAttribute), false)) { ExcelColumnNameAttribute x = (ExcelColumnNameAttribute)p.GetCustomAttribute(typeof(ExcelColumnNameAttribute)); shipmentColumnNames.Add(x?.ColumnName ?? p.Name); shipmentPropNames.Add(p.Name); } else { shipmentColumnNames.Add(p.Name); shipmentPropNames.Add(p.Name); } });
[AttributeUsage(AttributeTargets.Property)]
public class ExcelColumnNameAttribute:Attribute
{
     public string ColumnName { get; set; }
}

 

posted on 2023-11-30 17:45  LiXiang98  阅读(60)  评论(0)    收藏  举报