# Best way to locate Find on List<T> with reflection

I am locating the find method of List in C# with the single Expression type parameter

I am using the following ( where T is a List, in my case a SubSonic IActiveRecord )

MethodInfo info = typeof(T).GetMethods(BindingFlags.Static | BindingFlags.Public)
.FirstOrDefault(m => m.Name == "Find" && m.GetParameters().Count() == 1);


This works perfectly well, but feels clunky (especially the parameter count part) and I'm not sure how future proof it is.

• IEnumerable expose one single method named GetEnumerator... Mar 10, 2011 at 22:06
• @VirtualBlackFox It also exposes many extension methods in C#3+ for use with LINQ Mar 10, 2011 at 22:23
• 1.GetMethod on IEnumerable<T> will never return theses. 2.None is called "Find" in the framework. 3.Look like you are searching on a List<T> as this one define a one parameter "Find" taking a predicate. Mar 10, 2011 at 22:28
• @VirtualBlackFox Oh, you are correct. I always assumed it was an IEnumerable extension method, thanks. Question edited accordingly Mar 10, 2011 at 22:37
• Is there a reason you're not just using GetMethod? Mar 10, 2011 at 23:24