System.Linq.Dynamic.ExpressionParser.FindBestMethod C# (CSharp) Method

FindBestMethod() protected method

protected FindBestMethod ( IEnumerable candidates, Maybe methodName, Expression methodArgs, MethodBase &method ) : int
candidates IEnumerable
methodName Maybe
methodArgs System.Linq.Expressions.Expression
method System.Reflection.MethodBase
return int
		protected int FindBestMethod(IEnumerable<MethodBase> candidates, Maybe<string> methodName, Expression[] methodArgs, out MethodBase method)
		{
			IEnumerable<MethodBase> methodBases = candidates.Where(m => !methodName.HasValue || IsMethodSuitByName(methodName.Value, m));

			MethodData[] applicable = methodBases
				.Select(m => new MethodData { _methodBase = m, _parameters = m.GetParameters() })
				.Where(m => IsApplicable(m, methodArgs))
				.ToArray();

			if (applicable.Length > 1)
			{
				applicable = applicable.
					Where(m => applicable.All(n => m == n || IsBetterThan(methodArgs, m, n))).
					ToArray();
			}
			if (applicable.Length == 1)
			{
				MethodData md = applicable[0];
				for (int i = 0; i < methodArgs.Length; i++) { methodArgs[i] = md._args[i]; }
				method = md._methodBase;
			}
			else
			{
				method = null;
			}
			return applicable.Length;
		}
ExpressionParser