我有一个很长的条件声明:
public static DataGridColumn CreateAppropreateColumn(string path, PropertyInfo info, string header, IRepository repository)
{
DataGridColumn column = null;
if (info.GetCustomAttributes(typeof(DbComboBoxAttribute), true).Any())
{
column = CreateComboBoxColumn(path, info, header, repository);
}
else if (info.GetCustomAttributes(typeof(DescribedByteEnumComboBoxAttribute), true).Any())
{
column = CreateEnumComboBoxColumn(path, info, header);
}
else if (info.GetCustomAttributes(typeof(DropDownLazyLoadingDataGridAttribute), true).Any())
{
column = CreateDataGridDropDownLazyLoadingDataGridColumn(path, info, header, repository);
}
else if (info.GetCustomAttributes(typeof(DropDownTreeViewAttribute), true).Any())
{
column = CreateDataGridTreeViewColumn(path, info, header, repository);
}
//Other controls (Like drop down panels ... and so on ) can add here . . .
//}
else if (info.GetCustomAttributes(typeof(DatePickerAttribute), true).Any())
{
column = CreateDataGridDateColumn(path, info, header);
}
else if (info.GetCustomAttributes(typeof(YearPickerAttribute), true).Any())
{
column = CreateDataGridYearColumn(path, info, header);
}
else if (info.PropertyType == typeof(bool) || info.PropertyType == typeof(bool?))
{
column = CreateDataGridCheckBoxColumn(path, info, header);
}
else
{
column = CreateTextBoxColumn(path, info, header);
}
return Column;
}
我可以删除 ifs 吗?
谢谢你。