I\'ve run into a bit of a problem, which I simply cannot find a good work-around to.
I want to have these 3 overloads:
public IList GetList&
what about this?
public IList<T> GetList<T>(string query) where T : new()
{
// whatever you need to distinguish, this is a guess:
if (typeof(T).IsPrimitiveValue)
{
GetPrimitiveList<T>(query);
}
else if (typeof(T) == typeof(string))
{
GetStringList<T>(query);
}
else
{
GetEntityList<T>(query);
}
}
private IList<T> GetStringList<T>(string query)
private IList<T> GetPrimitiveList<T>(string query)
private IList<T> GetEntityList<T>(string query)
As you note; there aren't any good options for this. You might consider different names (rather than overloads) - GetStringList
etc.
However, I wonder whether it would be simpler to drop the constraint. A single type-check with "as" isn't exactly "heavy" type-casting, and it might save a lot of pain.