#region GridViewHead
public class GridViewHeadAttribute : Attribute
{
public GridViewHeadAttribute() { }
public GridViewHeadAttribute(string name)
{
Name = name;
}
public GridViewHeadAttribute(string name, int sort)
{
Name = name;
Sort = sort;
}
public string Name { get; set; }
public int Sort { get; set; }
}
public class GridViewHeadInfo
{
static Dictionary<string, string> dic = new Dictionary<string, string>();
static GridViewHeadInfo()
{
dic.Add("Name", "名字");
dic.Add("Code", "编号");
dic.Add("Sex", "性别");
}
public string Key { get; set; }
public string Value { get; set; }
public int Sort { get; set; }
public bool IsHide { get; set; }
public static List<GridViewHeadInfo> GetPropertyInfoList(Type type)
{
var propertyInfos = type.GetProperties();
List<GridViewHeadInfo> gridViewHeadInfos = new List<GridViewHeadInfo>();
int sort = 0;
foreach (var item in propertyInfos)
{
gridViewHeadInfos.Add(new GridViewHeadInfo()
{
Key = item.Name,
Value = dic.ContainsKey(item.Name) ? dic[item.Name] : "未定义",
Sort = sort,
});
sort++;
//是否存在特性
foreach (var attribute in item.GetCustomAttributes(typeof(GridViewHeadAttribute), true))
{
GridViewHeadAttribute gridViewHeadAttribute = attribute as GridViewHeadAttribute;
var gridViewHeadInfo = gridViewHeadInfos.Find(p => p.Key == item.Name);
if (gridViewHeadInfo == null)
{
gridViewHeadInfo = new GridViewHeadInfo();
gridViewHeadInfos.Add(gridViewHeadInfo);
}
gridViewHeadInfo.Key = item.Name;
gridViewHeadInfo.Value = gridViewHeadAttribute.Name;
if (gridViewHeadAttribute.Sort != 0)
{
gridViewHeadInfo.Sort = gridViewHeadAttribute.Sort;
}
}
}
return gridViewHeadInfos;
}
}
#endregion