private IServiceCallSite[] CreateArgumentCallSites( Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, bool throwIfCallSiteNotFound) { var parameterCallSites = new IServiceCallSite[parameters.Length]; for (var index = 0; index < parameters.Length; index++) { var callSite = CreateCallSite(parameters[index].ParameterType, callSiteChain); if (callSite == null && ParameterDefaultValue.TryGetDefaultValue(parameters[index], out var defaultValue)) { callSite = new ConstantCallSite(serviceType, defaultValue); } if (callSite == null) { if (throwIfCallSiteNotFound) { throw new InvalidOperationException(Resources.FormatCannotResolveService( parameters[index].ParameterType, implementationType)); } return(null); } parameterCallSites[index] = callSite; } return(parameterCallSites); }
private IServiceCallSite TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain) { if (serviceType == descriptor.ServiceType) { IServiceCallSite callSite; if (descriptor.ImplementationInstance != null) { callSite = new ConstantCallSite(descriptor.ServiceType, descriptor.ImplementationInstance); } else if (descriptor.ImplementationFactory != null) { callSite = new FactoryCallSite(descriptor.ServiceType, descriptor.ImplementationFactory); } else if (descriptor.ImplementationType != null) { callSite = CreateConstructorCallSite(descriptor.ServiceType, descriptor.ImplementationType, callSiteChain); } else { throw new InvalidOperationException("Invalid service descriptor"); } return(ApplyLifetime(callSite, descriptor, descriptor.Lifetime)); } return(null); }
protected override Expression VisitConstant(ConstantCallSite constantCallSite, ILEmitResolverBuilderContext argument) { AddConstant(argument, constantCallSite.DefaultValue); return null; }
protected override object VisitConstant(ConstantCallSite constantCallSite, ServiceProviderEngineScope scope) { return(constantCallSite.DefaultValue); }
protected override ILEmitCallSiteAnalysisResult VisitConstant(ConstantCallSite constantCallSite, object argument) => new ILEmitCallSiteAnalysisResult(ConstantILSize);
protected override object VisitConstant(ConstantCallSite constantCallSite, CallSiteFormatterContext argument) { argument.WriteProperty("value", constantCallSite.DefaultValue ?? ""); return(null); }
protected override Expression VisitConstant(ConstantCallSite constantCallSite, CallSiteExpressionBuilderContext context) { return(Expression.Constant(constantCallSite.DefaultValue)); }
protected abstract TResult VisitConstant(ConstantCallSite constantCallSite, TArgument argument);
protected override Expression BuildConstant(ConstantCallSite callSite) { return(Expression.Constant(callSite.DefaultValue)); }
protected abstract TResult BuildConstant(ConstantCallSite constantCallSite);
protected override Type VisitConstant(ConstantCallSite constantCallSite, CallSiteValidatorState state) => null;
protected override object BuildConstant(ConstantCallSite constantCallSite) { return(constantCallSite.DefaultValue); }