I have one Generic Method, where we can pass a T as a interface type. Method returns a list of data corresponding T type. I have 20-25 same condition for this method how can I optimize logic.
Class implements interface. example Student class implements IStudent interface.
public ObservableCollection<T> GetAll<T>()
{
try
{
if (typeof(T) == typeof(IStudent))
{
return GetAll<T, Student>();
}
else if (typeof(T) == typeof(IZone))
{
return GetAll<T, Zone>();
}
else if (typeof(T) == typeof(IEmployee))
{
return GetAll<T, Employee>();
}
else if (typeof(T) == typeof(ICourse))
{
return GetAll<T, Course>();
}
}
}
Here caller pass interface type T and I check type of T. I pass to other function T and class which will return list of T. Other function in base class which I can not change. Could anyone suggest me something about same.