コード例 #1
0
        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);
        }
コード例 #2
0
 protected abstract TResult VisitConstant(ConstantCallSite constantCallSite, TArgument argument);
コード例 #3
0
 protected override object VisitConstant(ConstantCallSite constantCallSite, ServiceProvider provider)
 {
     return(constantCallSite.DefaultValue);
 }
コード例 #4
0
 protected override Expression VisitConstant(ConstantCallSite constantCallSite, ParameterExpression provider)
 {
     return(Expression.Constant(constantCallSite.DefaultValue));
 }
コード例 #5
0
 protected override Type VisitConstant(ConstantCallSite constantCallSite, CallSiteValidatorState state) => null;