private static object ResolveLambdaExpressionBindTarget(string bindAs, LambdaRepository lambdaRepo, ScopeChain scopeChain) { Func <object> lambda = lambdaRepo.Resolve(bindAs, scopeChain); object target = lambda(); return(target); }
private static object ResolveScopeWalkBindTarget(string bindAs, LambdaRepository lambdaRepo, ScopeChain scopeChain) { int lastIdxOf; int depth = BindHelper.CountInstancesOfPattern(bindAs, @"..\", out lastIdxOf); object target = BindHelper.ResolveBindTarget(bindAs.Substring(lastIdxOf + 3, bindAs.Length - (depth * 3)), lambdaRepo, scopeChain, depth); return(target); }
private static object ResolveVariableReferenceBindTarget(string bindAs, LambdaRepository lambdaRepo, ScopeChain scopeChain) { object target = null; int dot = bindAs.IndexOf('.'); if (dot > -1) { target = scopeChain.AccessVariable(bindAs.Substring(0, dot)); scopeChain.Push(target); target = BindHelper.ResolveBindTarget(bindAs.Substring(++dot, bindAs.Length - dot), lambdaRepo, scopeChain); scopeChain.Pop(); } else { target = scopeChain.AccessVariable(bindAs); } return(target); }
public static object ResolveBindTarget(string bindAs, LambdaRepository lambdaRepo, ScopeChain scopeChain, int scopeLinkDepth = 0) { object target = null; object localScope = scopeChain.Peek(scopeLinkDepth); if (bindAs.Length == 1 && bindAs[0] == '$')//append bindto obj { target = localScope; } else if (bindAs[0] == '$' && bindAs[1] == '.')//reflect from bindto object { target = BindHelper.ResolveRootedBindTarget(bindAs, localScope); } else if (bindAs[0] == ':')//variable reference { target = BindHelper.ResolveVariableReferenceBindTarget(bindAs, lambdaRepo, scopeChain); } else if (bindAs[0] == '.' && bindAs[1] == '.' && bindAs[2] == '\\')//scope chain walk ..\ { target = BindHelper.ResolveScopeWalkBindTarget(bindAs, lambdaRepo, scopeChain); } else if (BindHelper.IsLambdaExpression(bindAs))//lambda expression { target = BindHelper.ResolveLambdaExpressionBindTarget(bindAs, lambdaRepo, scopeChain); } else//simple bind { target = ReflectionHelper.Expression.ReflectItem(localScope, bindAs); } return(target); }
private TemplateEngine WithLambdaRepository(LambdaRepository repo) { _lambdaRepo = repo; return(this); }