A lambda expression is convertible to either a delegate type or an expression tree with the right signature - but you need to specify which delegate type it is.
I think your code would be much simpler if you made this a generic method:
public static List<object> ConvertToListOfObjects<T>(List<T> list)
{
return list.ConvertAll<object>(t => t);
}
Then you just need to find and invoke that method generically:
MethodInfo method = typeof(Foo).GetMethod("ConvertToListOfObjects",
BindingFlags.Static | BindingFlags.Public);
Type listType = list.GetType().GetGenericArguments()[0];
MethodInfo concrete = method.MakeGenericMethod(new [] { listType });
List<object> objectList = (List<object>) concrete.Invoke(null,
new object[]{list});
Complete example:
using System;
using System.Reflection;
using System.Collections.Generic;
class Test
{
public static List<object> ConvertToListOfObjects<T>(List<T> list)
{
return list.ConvertAll<object>(t => t);
}
static void Main()
{
object list = new List<int> { 1, 2, 3, 4 };
MethodInfo method = typeof(Test).GetMethod("ConvertToListOfObjects",
BindingFlags.Static | BindingFlags.Public);
Type listType = list.GetType().GetGenericArguments()[0];
MethodInfo concrete = method.MakeGenericMethod(new [] { listType });
List<object> objectList = (List<object>) concrete.Invoke(null,
new object[] {list});
foreach (object o in objectList)
{
Console.WriteLine(o);
}
}
}