System.Linq.QueryableTransformer.GetMatchingMethod C# (CSharp) Method

GetMatchingMethod() static private method

static private GetMatchingMethod ( MethodInfo method, Type declaring ) : MethodInfo
method System.Reflection.MethodInfo
declaring System.Type
return System.Reflection.MethodInfo
		static MethodInfo GetMatchingMethod (MethodInfo method, Type declaring)
		{
			foreach (var candidate in declaring.GetMethods ()) {
				if (!MethodMatch (candidate, method))
					continue;

				if (method.IsGenericMethod)
					return candidate.MakeGenericMethodFrom (method);

				return candidate;
			}

			return null;
		}

Usage Example

        private static MethodInfo ReplaceQueryableMethod(MethodInfo method)
        {
            MethodInfo matchingMethod = QueryableTransformer.GetMatchingMethod(method, QueryableTransformer.GetTargetDeclaringType(method));

            if (matchingMethod != null)
            {
                return(matchingMethod);
            }
            throw new InvalidOperationException(string.Format("There is no method {0} on type {1} that matches the specified arguments", method.Name, method.DeclaringType.FullName));
        }