Given this class:
public class Foo { public void M1(int i){} public void M2(int i, string s){} public void M3(int i, string s){} public int M4(int i, string s){ return 0; } }
You can use the Reflection and LINQ bits:
Type t = typeof (Foo); var theMethods = t.GetMethods().Where(mi => { var p = mi.GetParameters(); if (p.Length != 2) return false; if (p[0].ParameterType != typeof(int) || p[1].ParameterType != typeof(string)) return false; return mi.ReturnType == typeof (void); });
or other syntax (which in this case is really nicer)
var theMethods = from mi in t.GetMethods() let p = mi.GetParameters() where p.Length == 2 && p[0].ParameterType == typeof (int) && p[1].ParameterType == typeof (string) && mi.ReturnType == typeof (void) select mi;
Test:
foreach (var methodInfo in theMethods) { Console.WriteLine(methodInfo.Name); }
Output:
M2 M3
Jamiec
source share