Consider the factory method below which takes some meta data and creates a column of the relevant type.
Its all good until I encounter a column which relies on some additional data (ColumnType.DropDownList). This needs some additional data (a list of values) for display purposes.
I dont want to provide this data at a meta data level so providing it when an object is created in the factory seems sensible. But I'm struggling for an elegant way to get the list into the factory method (SEE COMMENT: cant BE HARDCODED HERE!!!)
Any ideas? I'm open to any!
public static DetailEditorColumn<int> Create(ColumnMetaData metaData)
{
if (metaData.ColumnType == ColumnType.Rank)
{
return GridColumnBuilder<int>.GetRankColumn(metaData.DisplayOrder, metaData);
}
if (metaData.ColumnType == ColumnType.Decision)
{
return GridColumnBuilder<int>.GetDecisionColumn(metaData.DisplayOrder, metaData);
}
if (metaData.ColumnType == ColumnType.Date)
{
return GridColumnBuilder<int>.GetDateColumn(metaData.DisplayOrder, metaData);
}
if (metaData.ColumnType == ColumnType.DropDownList)
{
// TODO where the humf should this get plugged in!
// cant BE HARDCODED HERE!!!
DropDownList lookupList = new DropDownList()
{
new DropDownListOption() { Id = 1, Value = "Entry 1", ParenTId = null },
new DropDownListOption() { Id = 2, Value = "Entry 1", ParenTId = null },
new DropDownListOption() { Id = 3, Value = "Entry 1", ParenTId = null }
};
return GridColumnBuilder<int>.GetDropDownListColumn(metaData.DisplayOrder, metaData, lookupList);
}
throw new Exception("Column Type Not Supported " + metaData);
}