protected override async ValueTask CoreExpandTemplateAsync(ITextMetalContext templatingContext) { templatingContext.GetWildcardReplacer().GetByToken("yo", out object value); await templatingContext.CurrentOutput.TextWriter.WriteLineAsync(string.Format("test: yo={0}", value)); await templatingContext.CurrentOutput.EnterScopeAsync("", false, Encoding.Default); }
public static object printf(ITextMetalContext templatingContext, string[] parameters) { const int CNT_P = 2; // token, format object value; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } if ((object)parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (parameters.Length != CNT_P) { throw new InvalidOperationException(string.Format("printf expects '{1}' parameter(s) but received '{0}' parameter(s).", parameters.Length, CNT_P)); } var x = templatingContext.GetWildcardReplacer(); if (!x.GetByToken(parameters[0], out value)) { return(null); } return(string.Format(value?.ToString() ?? string.Empty, parameters[1])); //return value.SafeToString(parameters[1]); }
protected override void CoreExpandTemplate(ITextMetalContext templatingContext) { //templatingContext.RequestDebugger(); templatingContext.GetWildcardReplacer().GetByToken("yo", out object value); templatingContext.CurrentOutput.TextWriter.WriteLine("test: yo={0}", value); templatingContext.CurrentOutput.EnterScope("", false, Encoding.Default); }
protected override async ValueTask CoreExpandTemplateAsync(ITextMetalContext templatingContext) { string text; DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetWildcardReplacer(); text = templatingContext.Tokenizer.ExpandTokens(this.Value, dynamicWildcardTokenReplacementStrategy); await templatingContext.CurrentOutput.TextWriter.WriteAsync(text); }
public async ValueTask ExpandTemplateAsync(ITextMetalContext templatingContext) { DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetWildcardReplacer(); if (this.IsScopeBlock) { templatingContext.VariableTables.Push(new Dictionary <string, object>()); } await this.CoreExpandTemplateAsync(templatingContext); if (this.IsScopeBlock) { templatingContext.VariableTables.Pop(); } }