Based on Victor Rodriguez’s answer, we can develop another method for generics. In fact, the original solution can be reduced to only two lines:
public static bool IsGenericList(this object Value) { var t = Value.GetType(); return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>); } public static bool IsGenericList<T>(this object Value) { var t = Value.GetType(); return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<T>); }
James M Jan 17 '17 at 0:53 2017-01-17 00:53
source share