Checking type parameter of a generic method in C#
Yes: if (typeof(T) == typeof(MyClass)) { MyClass mc = (MyClass)(object) t; } else if (typeof(T) == typeof(List<MyClass>)) { List<MyClass> lmc = (List<MyClass>)(object) t; } It’s slightly odd that you need to go via a cast to object, but that’s just the way that generics work – there aren’t as many conversions from a generic type … Read more