I'd like to make some operations according to a given collection type (using reflexion), regardless of the generic type.
Here is my code:
void MyFct(Type a_type)
{
// Check if it's type of List<>
if (a_type.Name == "List`1")
{
// Do stuff
}
// Check if it's type of Dictionary<,>
else if (a_type.Name == "Dictionary`2")
{
// Do stuff
}
}
It works for now, but it gets obvious to me that it's not the most safe solution.
void MyFct(Type a_type)
{
// Check if it's type of List<>
if (a_type == typeof(List<>))
{
// Do stuff
}
// Check if it's type of Dictionary<,>
else if (a_type == typeof(Dictionary<,>))
{
// Do stuff
}
}
I tried that too, it actualy compiles but doesn't work... I also tried to test all interfaces of the given collection type, but it implies an exclusivity for interfaces in collections...
I hope I made myself clear, my english lack of training :)
a_type.ToString().
what does it say?