I have a generic method define as below
public T MyMethod<T>(extra params)
My method can receive and return either single entity type but also List. How can I find if T passed is a single entity type or a List and in this case how can I get the type of inner type T1?
Thanks
You can do this using methods of the Type
class:
var type = typeof(T);
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) {
var innerType = type.GetGenericArguments()[0];
}