I wrote this method:
public IGamePlugin[,] GetTable<T>()
{
Type t = typeof(T);
if (t is IFixedElement)
{
return fixedElements;
}
else if (t is IFixedTile)
{
return fixedTiles;
}
else
{
throw new NotSupportedException("Type:" + t.ToString() + " is not supported");
}
}
And I’m quite unsure if it is not wrong usage of generics. I like it better than using a simple parameter (string or maybe Type) because the syntax is clear on the calling side.
What do you think?
This really should be two separate functions,
GetElementsTableandGetTilesTable.To answer your question, it definitely is abuse of generics the way you’ve done it. But you’re right that using a parameter is also bad.