public void SetColumnNames <T>() { List <String> names = new List <String>(); foreach (PropertyInfo property in typeof(T).GetProperties()) { ColumnNameAttribute attr = property.GetCustomAttribute <ColumnNameAttribute>(); if (attr != null) { names.Add(attr.ActualName); } } SetColumnNames(names); }
public void AddLine <T>(T item) { Dictionary <String, String> row = new Dictionary <String, String>(); foreach (PropertyInfo property in typeof(T).GetProperties()) { ColumnNameAttribute attr = property.GetCustomAttribute <ColumnNameAttribute>(); if (attr != null) { Object thing = property.GetValue(item); if (thing == null) { thing = ""; } row.Add(attr.ActualName, thing.ToString()); } } AddLine(row); }