private IServiceCallSite[] PopulateCallSites( ServiceProvider provider, ISet <Type> callSiteChain, ParameterInfo[] parameters, bool throwIfCallSiteNotFound) { var parameterCallSites = new IServiceCallSite[parameters.Length]; for (var index = 0; index < parameters.Length; index++) { var callSite = provider.GetServiceCallSite(parameters[index].ParameterType, callSiteChain); if (callSite == null && parameters[index].HasDefaultValue) { callSite = new ConstantCallSite(parameters[index].DefaultValue); } if (callSite == null) { if (throwIfCallSiteNotFound) { throw new InvalidOperationException("不能解析服务。"); } return(null); } parameterCallSites[index] = callSite; } return(parameterCallSites); }
protected abstract TResult VisitConstant(ConstantCallSite constantCallSite, TArgument argument);
protected override object VisitConstant(ConstantCallSite constantCallSite, ServiceProvider provider) { return(constantCallSite.DefaultValue); }
protected override Expression VisitConstant(ConstantCallSite constantCallSite, ParameterExpression provider) { return(Expression.Constant(constantCallSite.DefaultValue)); }
protected override Type VisitConstant(ConstantCallSite constantCallSite, CallSiteValidatorState state) => null;