/// <summary> init : we don't have to do much. Init the tree (there /// shouldn't be one) and then see if interpolation is turned on. /// </summary> public override Object Init(IInternalContextAdapter context, Object data) { base.Init(context, data); /* * the stringlit is set at template parse time, so we can * do this here for now. if things change and we can somehow * create stringlits at runtime, this must * move to the runtime execution path * * so, only if interpolation is turned on AND it starts * with a " AND it has a directive or reference, then we * can interpolate. Otherwise, don't bother. */ interpolate = FirstToken.Image.StartsWith("\"") && ((FirstToken.Image.IndexOf('$') != -1) || (FirstToken.Image.IndexOf('#') != -1)); /* * get the contents of the string, minus the '/" at each end */ image = FirstToken.Image.Substring(1, (FirstToken.Image.Length - 1) - (1)); /* * tack a space on the end (dreaded <MORE> kludge) */ interpolateImage = string.Format("{0} ", image); if (interpolate) { /* * now parse and init the nodeTree */ TextReader br = new StringReader(interpolateImage); /* * it's possible to not have an initialization context - or we don't * want to trust the caller - so have a fallback value if so * * Also, do *not* dump the VM namespace for this template */ nodeTree = runtimeServices.Parse(br, (context != null) ? context.CurrentTemplateName : "StringLiteral", false); /* * init with context. It won't modify anything */ nodeTree.Init(context, runtimeServices); } return(data); }
private object EvaluateInPlace(string content, IInternalContextAdapter context) { try { SimpleNode inlineNode = runtimeServices.Parse(new StringReader(content), context.CurrentTemplateName, false); inlineNode.Init(context, runtimeServices); return(Evaluate(inlineNode, context)); } catch (Exception) { throw new ArgumentException(string.Format("Problem evaluating dictionary entry with content {0}", content)); } }