I have a c# method which passes a dictionary with generics, for example:
private void SaveData<T>(Dictionary<string, T> results) where T : class
{
var listOfResults = results.Select(x => x.Value).ToList();
// If T is a list
if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(List<>))
{
// HELP HERE, how do I collapse the list of lists?
}
else
{
SaveToTheDatabase(listOfResults);
}
}
We know that T could be a single value or it could be a list of values. The first if statement is supposed to check if T is a list. The else assumes it's a single value.
The spot where I have the comment, HELP HERE, how do I collapse the list of lists?
>
– Chase W. Jun 22 '18 at 16:52>`, and you don't know the `U`. The question by @DanielA.White makes sense because looks like you have to convert it to `List` and pass it to a generic method (not action) with `U` generic argument.
>().SelectMany(x => x).ToList();` which didn't work because the complier didn't know how to cast that.