public static InvokeMethod CreateMethodExpression(IContainerContext containerContext, ResolutionTarget[] parameters, MethodInfo methodInfo)
        {
            var strategyParameter = Expression.Constant(containerContext.ResolutionStrategy, typeof(IResolutionStrategy));
            var resolutionInfoParameter = Expression.Parameter(typeof(ResolutionInfo), "resolutionInfo");
            var instanceParameter = Expression.Parameter(typeof(object), "instance");
            var convertedInstance = Expression.Convert(instanceParameter, methodInfo.DeclaringType);

            var arguments = CreateExpressionFromResolutionTargets(parameters, strategyParameter, resolutionInfoParameter);

            var callExpression = Expression.Call(convertedInstance, methodInfo, arguments);
            return Expression.Lambda<InvokeMethod>(callExpression, resolutionInfoParameter, instanceParameter).Compile();
        }
Ejemplo n.º 2
0
 public Expression GetExpressionForResolutionTarget(ResolutionTarget resolutionTarget, ResolutionInfo resolutionInfo, Expression resolutionInfoExpression)
 {
     return this.resolutionStrategy.GetExpressionForResolutionTarget(resolutionTarget, resolutionInfo, resolutionInfoExpression);
 }
Ejemplo n.º 3
0
 public object EvaluateResolutionTarget(ResolutionTarget resolutionTarget,
     ResolutionInfo resolutionInfo)
 {
     return this.resolutionStrategy.EvaluateResolutionTarget(resolutionTarget, resolutionInfo);
 }
Ejemplo n.º 4
0
 private Expression CreateOverrideExpression(ResolutionTarget resolutionTarget, Expression resolutionInfoExpression)
 {
     var overrideManagerExpression = Expression.Property(resolutionInfoExpression, "OverrideManager");
     var callExpression = Expression.Call(overrideManagerExpression, "GetOverriddenValue", null, Expression.Constant(resolutionTarget.TypeInformation));
     return Expression.Convert(callExpression, resolutionTarget.TypeInformation.Type);
 }
Ejemplo n.º 5
0
 public Expression GetExpressionForResolutionTarget(ResolutionTarget resolutionTarget, ResolutionInfo resolutionInfo, Expression resolutionInfoExpression)
 {
     if (resolutionInfo.OverrideManager != null &&
         resolutionInfo.OverrideManager.ContainsValue(resolutionTarget.TypeInformation))
         return this.CreateOverrideExpression(resolutionTarget, resolutionInfoExpression);
     return resolutionTarget.ResolutionTargetValue != null ? Expression.Constant(resolutionTarget.ResolutionTargetValue) :
         resolutionTarget.Resolver.GetExpression(resolutionInfo, resolutionInfoExpression);
 }
Ejemplo n.º 6
0
 public object EvaluateResolutionTarget(ResolutionTarget resolutionTarget, ResolutionInfo resolutionInfo)
 {
     if (resolutionInfo.OverrideManager != null && resolutionInfo.OverrideManager.ContainsValue(resolutionTarget.TypeInformation))
         return resolutionInfo.OverrideManager.GetOverriddenValue(resolutionTarget.TypeInformation);
     return resolutionTarget.ResolutionTargetValue ?? resolutionTarget.Resolver.Resolve(resolutionInfo);
 }
 private static Expression CreateResolutionTargetExpression(ResolutionTarget resolutionTarget, Expression strategyParameter,
     Expression resolutionInfoParameter)
 {
     var target = Expression.Constant(resolutionTarget, typeof(ResolutionTarget));
     var evaluate = Expression.Call(strategyParameter, "EvaluateResolutionTarget", null, target, resolutionInfoParameter);
     return Expression.Convert(evaluate, resolutionTarget.TypeInformation.Type);
 }