I need to be able to get something similar to the following to work:
Type type = ??? // something decided at runtime with .GetType or typeof;
object[] entity
what about ...
public static IList OfTypeToList(this IEnumerable source, Type type)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
return
(IList) Activator.CreateInstance(
typeof(List<>)
.MakeGenericType(type),
typeof(System.Linq.Enumerable)
.GetMethod(nameof(System.Linq.Enumerable.OfType),
BindingFlags.Static | BindingFlags.Public)
.MakeGenericMethod(type)
.Invoke(null, new object[] { source }));
}