private static List<MethodBase> GetInterfaceMethods(Type targetType, string methodName, IList<Type> typeArgs, int arity)
{
BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod;
List<Type> interfaces = new List<Type>();
interfaces.Add(targetType);
interfaces.AddRange(targetType.GetInterfaces());
List<MethodBase> infos = new List<MethodBase>();
foreach (Type type in interfaces)
{
IEnumerable<MethodInfo> einfo
= type.GetMethods(flags).Where(info => info.Name == methodName && info.GetParameters().Length == arity);
foreach (MethodInfo minfo in einfo)
if (typeArgs == null && !minfo.ContainsGenericParameters)
infos.Add(minfo);
else if (typeArgs != null && minfo.ContainsGenericParameters)
infos.Add(minfo.MakeGenericMethod(typeArgs.ToArray<Type>()));
}
return infos;
}