コード例 #1
0
                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);
                }
コード例 #2
0
        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]);
        }
コード例 #3
0
                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);
                }
コード例 #4
0
        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);
        }
コード例 #5
0
        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();
            }
        }