Does anyone have any clue on why calling GetRuntimeMethod is returning null for the following case?
_toListMethod = typeof(Enumerable).GetRuntimeMethod("ToList", new Type[] { typeof(IEnumerable<>) });
It should work just like it does for:
_castMethod = typeof(Enumerable).GetRuntimeMethod("Cast", new Type[] { typeof(IEnumerable) });
I tried to debug this by running the following code:
var bah = typeof (Enumerable).GetRuntimeMethods().Where(m => m.Name.Contains("ToList"));
var derp = bah.First().GetParameters();
To my surprise, the first line returns a collection which contains the MethodInfo I am trying to get and the second line confirms that the expected paramter type is IEnumerable<>.
The two method signatures, Cast and ToList, are similar and I cannot see any reason why getting the MethodInfo for ToList would fail.
This code is running on a Portable Class Library with TargetFrameworkProfile set to Profile78.
Thanks!
Update: Until I have a good solution, there is one ugly workaround which works for me:
_toListMethod = typeof(Enumerable).GetRuntimeMethods().First(m => m.Name.Contains("ToList"));