代码:
public Dictionary<string, string> XXXModelColumnName
{
get
{
var dic = new Dictionary<string, string>();
PropertyInfo[] fields = typeof(XXXModel).GetProperties();
foreach (PropertyInfo field in fields)
{
var fieldName = field.Name;
var displayName = field.GetCustomAttribute<DisplayNameAttribute>();
dic.Add(fieldName, displayName == null ? fieldName : displayName.DisplayName);
}
return dic;
}
}