protected override Expression VisitConstructor(ConstructorCallSite callSite, CallSiteExpressionBuilderContext context) { var parameters = callSite.ConstructorInfo.GetParameters(); return(Expression.New( callSite.ConstructorInfo, callSite.ParameterCallSites.Select((c, index) => Convert(VisitCallSite(c, context), parameters[index].ParameterType)))); }
protected override Expression VisitConstructor(ConstructorCallSite constructorCallSite, ILEmitResolverBuilderContext argument) { // new T([create arguments]) foreach (var parameterCallSite in constructorCallSite.ParameterCallSites) { VisitCallSite(parameterCallSite, argument); } argument.Generator.Emit(OpCodes.Newobj, constructorCallSite.ConstructorInfo); return null; }
protected override ILEmitCallSiteAnalysisResult VisitConstructor(ConstructorCallSite constructorCallSite, object argument) { var result = new ILEmitCallSiteAnalysisResult(ConstructorILSize); foreach (var callSite in constructorCallSite.ParameterCallSites) { result = result.Add(VisitCallSite(callSite, argument)); } return(result); }
protected override Type VisitConstructor(ConstructorCallSite constructorCallSite, CallSiteValidatorState state) { Type result = null; foreach (var parameterCallSite in constructorCallSite.ParameterCallSites) { var scoped = VisitCallSite(parameterCallSite, state); if (result == null) { result = scoped; } } return(result); }
protected override object VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) { object[] parameterValues = new object[constructorCallSite.ParameterCallSites.Length]; for (var index = 0; index < parameterValues.Length; index++) { parameterValues[index] = VisitCallSite(constructorCallSite.ParameterCallSites[index], scope); } try { var obj = constructorCallSite.ConstructorInfo.Invoke(parameterValues); var interceptors = InterceptorRuntimeCreate.CreatedInterceptors; var implementName = constructorCallSite.ImplementationType.FullName; if (interceptors != null && interceptors.Count > 0 && InterceptorRuntimeCreate.CanIntercept(implementName)) { Castle.DynamicProxy.ProxyGenerator generator = new Castle.DynamicProxy.ProxyGenerator(); if (constructorCallSite.ServiceType.IsInterface) { try { obj = generator.CreateInterfaceProxyWithTarget(constructorCallSite.ServiceType, obj, interceptors.ToArray()); } catch (Exception) { // ignored } } else if (constructorCallSite.ServiceType.IsClass && !constructorCallSite.ServiceType.IsAbstract && !constructorCallSite.ServiceType.IsSealed) { obj = generator.CreateClassProxyWithTarget(constructorCallSite.ServiceType, obj, parameterValues, interceptors.ToArray()); } } return(obj); } catch (Exception ex) when(ex.InnerException != null) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); // The above line will always throw, but the compiler requires we throw explicitly. throw; } }
protected override object VisitConstructor(ConstructorCallSite constructorCallSite, CallSiteFormatterContext argument) { argument.WriteProperty("implementationType", constructorCallSite.ImplementationType); if (constructorCallSite.ParameterCallSites.Length > 0) { argument.StartProperty("arguments"); CallSiteFormatterContext childContext = argument.StartArray(); foreach (ServiceCallSite parameter in constructorCallSite.ParameterCallSites) { childContext.StartArrayItem(); VisitCallSite(parameter, childContext); } argument.EndArray(); } return(null); }
protected override Expression VisitConstructor(ConstructorCallSite callSite, CallSiteExpressionBuilderContext context) { var parameters = callSite.ConstructorInfo.GetParameters(); Expression[] parameterExpressions; if (callSite.ParameterCallSites.Length == 0) { parameterExpressions = Array.Empty <Expression>(); } else { parameterExpressions = new Expression[callSite.ParameterCallSites.Length]; for (int i = 0; i < parameterExpressions.Length; i++) { parameterExpressions[i] = Convert(VisitCallSite(callSite.ParameterCallSites[i], context), parameters[i].ParameterType); } } return(Expression.New(callSite.ConstructorInfo, parameterExpressions)); }
protected override object BuildConstructor(ConstructorCallSite constructorCallSite) { object[] parameterValues; if (constructorCallSite.ParameterCallSites.Length == 0) { parameterValues = Array.Empty <object>(); } else { parameterValues = new object[constructorCallSite.ParameterCallSites.Length]; for (var index = 0; index < parameterValues.Length; index++) { parameterValues[index] = Build(constructorCallSite.ParameterCallSites[index]); } } return(constructorCallSite.ConstructorInfo.Invoke(parameterValues)); }
protected override Expression BuildConstructor(ConstructorCallSite callSite) { var ParameterCallSites = callSite.ParameterCallSites; Expression[] parameterExpressions = null; if (ParameterCallSites.Length == 0) { parameterExpressions = Array.Empty <Expression>(); } else { var parameters = callSite.ConstructorInfo.GetParameters(); parameterExpressions = new Expression[ParameterCallSites.Length]; for (int i = 0; i < parameters.Length; i++) { parameterExpressions[i] = Convert(Build(ParameterCallSites[i]), parameters[i].ParameterType); } } return(Expression.New(callSite.ConstructorInfo, parameterExpressions)); }
protected abstract TResult VisitConstructor(ConstructorCallSite constructorCallSite, TArgument argument);
protected abstract TResult BuildConstructor(ConstructorCallSite constructorCallSite);