Sample code:
using System.Collections.Generic;
...
// could return anything.
private object GetObject(int code)
{
object obj = null;
if (code == 10)
{
var list1 = new List<Tuple<int, string>>();
list1.Add(new Tuple<int, string>(2, "blah"));
obj = list1;
}
else if (code == 20)
{
obj = "hello";
}
else if (code == 30)
{
var list2 = new List<string>();
list2.Add("o");
obj = list2;
}
// else etc, etc.
return obj;
}
private bool DoAction(int code)
{
object obj = GetObject(code);
bool isListT = ???
return isListT;
}
In code above, GetObject could return any type of object.
Inside DoAction, after calling GetObject, I want to be able to tell if the returned obj is any type of System.Collections.Generic.List<T>
. I don't care (nor may know) what T is. So DoAction(10) and DoAction(30) should return true, and DoAction(20) would return false.