private static bool CanResolveParameter(ICherryServiceLocatorAndRegistry current, ParameterInfo constructorParameterInfo, InjectionParameter[] parameters) { if (parameters == null || parameters.Length == 0) { // Shotcut when no parameters provided return current.CanGet(constructorParameterInfo.ParameterType); } InjectionParameter namedParameter = parameters.SingleOrDefault(p => p.Key == constructorParameterInfo.Name); if (namedParameter != null) { return true; } InjectionParameter unnamedParameter = parameters.SingleOrDefault( p => string.IsNullOrEmpty(p.Key) && !ReferenceEquals(p.Value, null) && constructorParameterInfo.ParameterType.IsInstanceOfType(p.Value)); if (unnamedParameter != null) { return true; } return current.CanGet(constructorParameterInfo.ParameterType); }
private static object ResolveParameter(ICherryServiceLocatorAndRegistry original, ICherryServiceLocatorAndRegistry current, ParameterInfo[] constructorParameterInfos, int i, InjectionParameter[] parameters) { ParameterInfo constructorParameterInfo = constructorParameterInfos[i]; if (parameters == null || parameters.Length == 0) { // Shotcut when no parameters provided return current.Get(original, constructorParameterInfo.ParameterType); } InjectionParameter namedParameter = parameters.SingleOrDefault(p => p.Key == constructorParameterInfo.Name); if (namedParameter != null) { return namedParameter.Value; } // No matching named parameter found, so lets try if we have a single parameter that mathes the constructor parameter type InjectionParameter unnamedParameter = parameters.SingleOrDefault( p => string.IsNullOrEmpty(p.Key) && !ReferenceEquals(p.Value, null) && constructorParameterInfo.ParameterType.IsInstanceOfType(p.Value)); if (unnamedParameter != null) { return unnamedParameter.Value; } return current.Get(original, constructorParameterInfo.ParameterType); }