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(); }
public Expression GetExpressionForResolutionTarget(ResolutionTarget resolutionTarget, ResolutionInfo resolutionInfo, Expression resolutionInfoExpression) { return this.resolutionStrategy.GetExpressionForResolutionTarget(resolutionTarget, resolutionInfo, resolutionInfoExpression); }
public object EvaluateResolutionTarget(ResolutionTarget resolutionTarget, ResolutionInfo resolutionInfo) { return this.resolutionStrategy.EvaluateResolutionTarget(resolutionTarget, resolutionInfo); }
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); }
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); }
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); }