System.Linq.QueryableTransformer.MethodMatch C# (CSharp) Метод

MethodMatch() статический приватный Метод

static private MethodMatch ( MethodInfo candidate, MethodInfo method ) : bool
candidate System.Reflection.MethodInfo
method System.Reflection.MethodInfo
Результат bool
		static bool MethodMatch (MethodInfo candidate, MethodInfo method)
		{
			if (candidate.Name != method.Name)
				return false;

			if (!HasExtensionAttribute (candidate))
				return false;

			var parameters = method.GetParameterTypes ();

			if (parameters.Length != candidate.GetParameters ().Length)
				return false;

			if (method.IsGenericMethod) {
				if (!candidate.IsGenericMethod)
					return false;

				if (candidate.GetGenericArguments ().Length != method.GetGenericArguments ().Length)
					return false;

				candidate = candidate.MakeGenericMethodFrom (method);
			}

			if (!TypeMatch (candidate.ReturnType, method.ReturnType))
				return false;

			var candidate_parameters = candidate.GetParameterTypes ();

			if (candidate_parameters [0] != GetComparableType (parameters [0]))
				return false;

			for (int i = 1; i < candidate_parameters.Length; ++i)
				if (!TypeMatch (candidate_parameters [i], parameters [i]))
					return false;

			return true;
		}

Usage Example

        private static MethodInfo GetMatchingMethod(MethodInfo method, Type declaring)
        {
            MethodInfo[] methods = declaring.GetMethods();
            int          i       = 0;

            while (i < methods.Length)
            {
                MethodInfo methodInfo = methods[i];
                if (!QueryableTransformer.MethodMatch(methodInfo, method))
                {
                    i++;
                }
                else
                {
                    if (method.IsGenericMethod)
                    {
                        return(methodInfo.MakeGenericMethodFrom(method));
                    }
                    return(methodInfo);
                }
            }
            return(null);
        }