perf: Potential optimization when searching for Constructors/Methods

This commit is contained in:
Chris Cameron
2020-03-27 14:50:02 -04:00
parent c1418ae4e2
commit b29ae4c8c8

View File

@@ -51,7 +51,15 @@ namespace ICD.Common.Utils
if (parameters == null)
throw new ArgumentNullException("parameters");
IEnumerable<Type> parameterTypes = method.GetParameters().Select(p => (Type)p.ParameterType);
ParameterInfo[] methodParameters = method.GetParameters();
// Bail early if the counts don't match
ICollection<object> parametersCollection = parameters as ICollection<object>;
if (parametersCollection != null && parametersCollection.Count != methodParameters.Length)
return false;
// Compare the parameters to the objects
IEnumerable<Type> parameterTypes = methodParameters.Select(p => (Type)p.ParameterType);
return ParametersMatchTypes(parameterTypes, parameters);
}