I have a defined generic type and custom data annotations. I want to get data annotations of this.
GetCustomAttributes not working because it's a generic type.
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;
}
Aucun commentaire:
Enregistrer un commentaire