protected override Expression VisitPathExpression(PathExpression pex) { var bindingContext = CompilationContext.Args.BindingContext; var configuration = CompilationContext.Configuration; var pathInfo = PathInfoStore.Current.GetOrAdd(pex.Path); var resolvePath = Call(() => PathResolver.ResolvePath(bindingContext, pathInfo)); if (pex.Context == PathExpression.ResolutionContext.Parameter) { return(resolvePath); } if (pathInfo.IsVariable || pathInfo.IsThis) { return(resolvePath); } if (!pathInfo.IsValidHelperLiteral && !configuration.Compatibility.RelaxedHelperNaming) { return(resolvePath); } var pathInfoLight = new PathInfoLight(pathInfo); if (!configuration.Helpers.TryGetValue(pathInfoLight, out var helper)) { // TODO: use IHelperResolver here as well var lateBindHelperDescriptor = new LateBindHelperDescriptor(pathInfo); helper = new Ref <IHelperDescriptor <HelperOptions> >(lateBindHelperDescriptor); configuration.Helpers.AddOrReplace(pathInfoLight, helper); } else if (configuration.Compatibility.RelaxedHelperNaming) { pathInfoLight = pathInfoLight.TagComparer(); if (!configuration.Helpers.ContainsKey(pathInfoLight)) { var lateBindHelperDescriptor = new LateBindHelperDescriptor(pathInfo); helper = new Ref <IHelperDescriptor <HelperOptions> >(lateBindHelperDescriptor); configuration.Helpers.AddOrReplace(pathInfoLight, helper); } } var options = New(() => new HelperOptions(pathInfo, bindingContext)); var context = New(() => new Context(bindingContext)); var argumentsArg = New(() => new Arguments(0)); return(Call(() => helper.Value.Invoke(options, context, argumentsArg))); }
protected override Expression VisitPathExpression(PathExpression pex) { var context = CompilationContext.Args.BindingContext; var configuration = CompilationContext.Configuration; var pathInfo = configuration.PathInfoStore.GetOrAdd(pex.Path); var resolvePath = Call(() => PathResolver.ResolvePath(context, pathInfo)); if (pex.Context == PathExpression.ResolutionContext.Parameter) { return(resolvePath); } if (pathInfo.IsVariable || pathInfo.IsThis) { return(resolvePath); } if (!pathInfo.IsValidHelperLiteral && !configuration.Compatibility.RelaxedHelperNaming) { return(resolvePath); } var pathInfoLight = new PathInfoLight(pathInfo); if (!configuration.Helpers.TryGetValue(pathInfoLight, out var helper)) { helper = new StrongBox <HelperDescriptorBase>(new LateBindHelperDescriptor(pathInfo, configuration)); configuration.Helpers.Add(pathInfoLight, helper); } else if (configuration.Compatibility.RelaxedHelperNaming) { pathInfoLight = pathInfoLight.TagComparer(); if (!configuration.Helpers.ContainsKey(pathInfoLight)) { helper = new StrongBox <HelperDescriptorBase>(new LateBindHelperDescriptor(pathInfo, configuration)); configuration.Helpers.Add(pathInfoLight, helper); } } var argumentsArg = New(() => new Arguments(0)); return(context.Call(o => helper.Value.ReturnInvoke(o, o.Value, argumentsArg))); }