I have following generic class:
public class SearchModel<T>
{
public string Name { get; set; }
public int? UserId { get; set; }
public List<T> result { get; set; }
}
public class A{
..
..
}
public class B{
..
..
}
and List in SearchModel class can be of type A/B. Now I have these two function calls which gives me appropriate results.
public List<A> SearchApplicationsForA(SearchModel<A> model){
}
public List<B> SearchApplicationsForB(SearchModel<B> model){
}
I was wondering if I can write a generic function which can identify the type of T and calls respective functions. For eg.
public List<T> SearchApplications<T>(SearchModel<T> model)
{
if (typeof(T) == typeof(A))
{
return SearchVerificationsForA(model);
}
else if (typeof(T) == typeof(B))
{
return SearchApplicationsForB(model);
}
}
Is it possible to write such functions?