Let say I have a generic member in a class or method, so:
public class Foo
{
public List Bar { get; set; }
public void Baz()
{
With the following extension method you can get away without reflection:
public static Type GetListType(this List _)
{
return typeof(T);
}
Or more general:
public static Type GetEnumeratedType(this IEnumerable _)
{
return typeof(T);
}
Usage:
List list = new List { "a", "b", "c" };
IEnumerable strings = list;
IEnumerable