コード例 #1
0
        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();
        }
コード例 #2
0
 public Expression GetExpressionForResolutionTarget(ResolutionTarget resolutionTarget, ResolutionInfo resolutionInfo, Expression resolutionInfoExpression)
 {
     return this.resolutionStrategy.GetExpressionForResolutionTarget(resolutionTarget, resolutionInfo, resolutionInfoExpression);
 }
コード例 #3
0
 public object EvaluateResolutionTarget(ResolutionTarget resolutionTarget,
     ResolutionInfo resolutionInfo)
 {
     return this.resolutionStrategy.EvaluateResolutionTarget(resolutionTarget, resolutionInfo);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #7
0
 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);
 }