Get the info method for Enumerable.DefaultIfEmpty

I am creating some Linq expression and trying to get MethodInfo for IEnumerable.DefaultIfEmpty ( http://msdn.microsoft.com/en-us/library/bb360179.aspx ). It seemed like a simple task, but I do not know why it does not work.

 typeof(Enumerable).GetMethod("DefaultIfEmpty", new[] { typeof(IEnumerable<>) }); typeof(Enumerable).GetMethod("DefaultIfEmpty", new[] { typeof(IEnumerable<>).MakeGenericType(typeof(WorkitemListModel)) }); 
+4
source share
1 answer

Getting common methods is a pain, to be honest. I do not know a better way than using:

 var method = typeof(Enumerable).GetMethods() .Where(m => m.Name == "DefaultIfEmpty") .Where(m => m.GetParameters().Length == 1) .Single(); 

To call GetMethod , you will need to have the exact correct type of the parameter, including the parameter of the correct type for the parameter. As soon as you get it, as soon as you can do it, but until then I think that all this is available :(

+5
source

All Articles