我有一个已定义的通用类型和自定义数据注释。我想获取数据注释。
GetCustomAttributes不起作用,因为它是通用类型。
public List<ColumnFilter> SetColumnFilters()
{
ColumnFilter columnFilter;
List<ColumnFilter> columnFilters = new List<ColumnFilter>();
foreach (var prop in typeof(T).GetProperties())
{
columnFilter = new ColumnFilter();
columnFilter.Field = prop.Name;
Type type = prop.GetType();
if (type is Enum)
{
columnFilter.FieldType = ColumnFilterType.DropDown;
}
else if (type is DateTime)
{
columnFilter.FieldType = ColumnFilterType.DatePicker;
}
else
{
columnFilter.FieldType = ColumnFilterType.Input;
}
columnFilters.Add(columnFilter);
}
return columnFilters;
}