Type FindTaskType(Type t) { while (t.GetGenericTypeDefinition() != typeof(Task<>)) { t = t.GetTypeInfo().BaseType; } return t; } }