I know I could use a technique like in this question to get my method.
E.g
MethodInfo firstMethod = typeof(Enumerable)
.GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(m => m.Name == "FirstOrDefault" && m.GetParameters().Length == 1)
I want to shortcut that process though.
I'm looking for Enumerable.FirstOrDefault Method (IEnumerable)
I've tried both
// I'm just using string just as an example.
var enumerableType = typeof(IEnumerable<>).MakeGenericType(typeof(string));
MethodInfo firstMethod = typeof(Enumerable)
.GetMethod("FirstOrDefault", new Type[] { enumerableType });
and
MethodInfo firstMethod = typeof(Enumerable)
.GetMethod("FirstOrDefault", Type.EmptyTypes);
But both return null
.
What would be the correct approach?