/// <summary> /// Evaluates the evaluation expression against a data context, optionally setting the console color if the expression contains those parameters /// </summary> /// <param name="context">The datta context to evaluate against</param> /// <returns>The result of the evaluation as a ConsoleString</returns> public ConsoleString Evaluate(DocumentRendererContext context) { context.LocalVariables.PushConsoleColors(FG, BG); try { var eval = context.EvaluateExpression(this.EvalToken.Value); if (eval == null) { return(ConsoleString.Empty); } else { if (eval is ConsoleString) { return((ConsoleString)eval); } else if (eval is string) { return(new ConsoleString(eval as string, context.LocalVariables.CurrentForegroundColor, context.LocalVariables.CurrentBackgroundColor)); } else { var result = eval.ToString(); var ret = context.RenderDynamicContent(result, this.EvalToken); return(ret); } } } finally { context.LocalVariables.PopConsoleColors(); } }
/// <summary> /// Evaluates the evaluation expression against a data context, optionally setting the console color if the expression contains those parameters /// </summary> /// <param name="context">The datta context to evaluate against</param> /// <returns>The result of the evaluation as a ConsoleString</returns> public ConsoleString Evaluate(DocumentRendererContext context) { context.LocalVariables.PushConsoleColors(FG, BG); try { var eval = context.EvaluateExpression(this.EvalToken.Value); if (eval == null) { return ConsoleString.Empty; } else { if (eval is ConsoleString) { return (ConsoleString)eval; } else if(eval is string) { return new ConsoleString(eval as string, context.LocalVariables.CurrentForegroundColor, context.LocalVariables.CurrentBackgroundColor); } else { var result = eval.ToString(); var ret = context.RenderDynamicContent(result, this.EvalToken); return ret; } } } finally { context.LocalVariables.PopConsoleColors(); } }