From 47c927838e1aef1041502b0545d6bdfae71c0170 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 26 Jan 2021 16:59:53 -0500 Subject: [PATCH] Remove more LINQ from DependencyInjection --- .../src/ServiceLookup/CallSiteFactory.cs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs b/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs index 42c44e3053a62e..d7e6fb0e720adb 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs @@ -285,7 +285,6 @@ private ServiceCallSite CreateConstructorCallSite( } parameterCallSites = CreateArgumentCallSites( - serviceType, implementationType, callSiteChain, parameters, @@ -304,7 +303,6 @@ private ServiceCallSite CreateConstructorCallSite( ParameterInfo[] parameters = constructors[i].GetParameters(); ServiceCallSite[] currentParameterCallSites = CreateArgumentCallSites( - serviceType, implementationType, callSiteChain, parameters, @@ -324,19 +322,24 @@ private ServiceCallSite CreateConstructorCallSite( if (bestConstructorParameterTypes == null) { - bestConstructorParameterTypes = new HashSet( - bestConstructor.GetParameters().Select(p => p.ParameterType)); + bestConstructorParameterTypes = new HashSet(); + foreach (ParameterInfo p in bestConstructor.GetParameters()) + { + bestConstructorParameterTypes.Add(p.ParameterType); + } } - if (!bestConstructorParameterTypes.IsSupersetOf(parameters.Select(p => p.ParameterType))) + foreach (ParameterInfo p in parameters) { - // Ambiguous match exception - string message = string.Join( - Environment.NewLine, - SR.Format(SR.AmbiguousConstructorException, implementationType), - bestConstructor, - constructors[i]); - throw new InvalidOperationException(message); + if (!bestConstructorParameterTypes.Contains(p.ParameterType)) + { + // Ambiguous match exception + throw new InvalidOperationException(string.Join( + Environment.NewLine, + SR.Format(SR.AmbiguousConstructorException, implementationType), + bestConstructor, + constructors[i])); + } } } } @@ -360,7 +363,6 @@ private ServiceCallSite CreateConstructorCallSite( } private ServiceCallSite[] CreateArgumentCallSites( - Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters,