in src/TestFramework/Extension.Desktop/PrivateObject.cs [833:911]
private LinkedList<MethodInfo> GetMethodCandidates(string methodName, Type[] parameterTypes, Type[] typeArguments, BindingFlags bindingFlags, ParameterModifier[] modifiers)
{
Debug.Assert(!string.IsNullOrEmpty(methodName), "methodName should not be null.");
Debug.Assert(parameterTypes != null, "parameterTypes should not be null.");
Debug.Assert(typeArguments != null, "typeArguments should not be null.");
LinkedList<MethodInfo> methodCandidates = new LinkedList<MethodInfo>();
if (!this.GenericMethodCache.TryGetValue(methodName, out var methods))
{
return methodCandidates;
}
Debug.Assert(methods != null, "methods should not be null.");
foreach (MethodInfo candidate in methods)
{
bool paramMatch = true;
ParameterInfo[] candidateParams = null;
Type[] genericArgs = candidate.GetGenericArguments();
Type sourceParameterType = null;
if (genericArgs.Length != typeArguments.Length)
{
continue;
}
// Since we can't just get the correct MethodInfo from Reflection,
// we will just match the number of parameters, their order, and their type
var methodCandidate = candidate;
candidateParams = methodCandidate.GetParameters();
if (candidateParams.Length != parameterTypes.Length)
{
continue;
}
// Exact binding
if ((bindingFlags & BindingFlags.ExactBinding) != 0)
{
int i = 0;
foreach (ParameterInfo candidateParam in candidateParams)
{
sourceParameterType = parameterTypes[i++];
if (candidateParam.ParameterType.ContainsGenericParameters)
{
// Since we have a generic parameter here, just make sure the IsArray matches.
if (candidateParam.ParameterType.IsArray != sourceParameterType.IsArray)
{
paramMatch = false;
break;
}
}
else
{
if (candidateParam.ParameterType != sourceParameterType)
{
paramMatch = false;
break;
}
}
}
if (paramMatch)
{
methodCandidates.AddLast(methodCandidate);
continue;
}
}
else
{
methodCandidates.AddLast(methodCandidate);
}
}
return methodCandidates;
}