Пример #1
0
        static void Main(string[] args)
        {
            Template template     = new Template();
            string   templateText =
                @"<% var now = new Date(); %>
Hello <%= Name %>!
It's <%= now.toDateString() %>";

            template.LoadText(templateText, "Name");
            string templateResult = template.Run(new Dictionary <string, object> {
                { "Name", "Jone Doe" }
            });

            Console.WriteLine(templateResult);

            // Custom template
            Template customTemplate = new CustomTemplate();

            customTemplate.LoadText(
                @"Hello {{Name}}!
It's {{Date:yyyy/MM/dd}}
My name is {{CurrentUser}}", "Name", "Date");

            string sourceCode           = customTemplate.Parsed.SourceCode;
            string customTemplateResult = customTemplate.Run(new Dictionary <string, object> {
                { "Name", "Jone Doe" }, { "Date", DateTime.Now }
            });

            Console.WriteLine(customTemplateResult);
        }
Пример #2
0
        static void Main(string[] args)
        {
            Template template = new Template();
            string templateText =
@"<% var now = new Date(); %>
Hello <%= Name %>!
It's <%= now.toDateString() %>";
            template.LoadText(templateText, "Name");
            string templateResult = template.Run(new Dictionary<string, object> { { "Name", "Jone Doe" } });
            Console.WriteLine(templateResult);

            // Custom template
            Template customTemplate = new CustomTemplate();
            customTemplate.LoadText(
@"Hello {{Name}}!
It's {{Date:yyyy/MM/dd}}
My name is {{CurrentUser}}", "Name", "Date");

            string sourceCode = customTemplate.Parsed.SourceCode;
            string customTemplateResult = customTemplate.Run(new Dictionary<string, object> { { "Name", "Jone Doe" }, { "Date", DateTime.Now } });
            Console.WriteLine(customTemplateResult);
        }