I want to replace switch statement with dynamic code so that I could pass dynamic type to generic class
This is the code that I have written, but as a new type is added I should add another case and it violates Open Closed Principle.
public ActionResult ManageData(ManageDataType manageDataType)
{
var result = new List<ManageDataCommon>();
switch (manageDataType)
{
case ManageDataType.Shift:
result = new BaseData<Shift>().GetSharedData();
break;
case ManageDataType.ShiftManager:
result = new BaseData<ShiftManager>().GetSharedData();
break;
}
return View(result);
}
And the code in view is:
<a href="@Url.Action("ManageData", "BaseData",
new {manageDataType= ManageDataType.Shift })"
<a href="@Url.Action("ManageData", "BaseData",
new {manageDataType= ManageDataType.ShiftManager})"
I like to implement code like this:
public ActionResult ManageData(T genericType)
{
var result = new BaseData<genericType>().GetSharedData();
return View(result);
}