0
|
1 namespace RazorEngine.Hosts.Console
|
|
2 {
|
|
3 using System;
|
|
4 using System.Linq;
|
|
5
|
|
6 using Compilation;
|
|
7 using Templating;
|
|
8
|
|
9 class Program
|
|
10 {
|
|
11 static void Main(string[] args)
|
|
12 {
|
|
13 CompilerServiceBuilder.SetCompilerServiceFactory(new DefaultCompilerServiceFactory());
|
|
14
|
|
15 using (var service = new TemplateService())
|
|
16 {
|
|
17 const string template = "<h1>Age: @Model.Age</h1>";
|
|
18 var expected = Enumerable.Range(1, 10).Select(i => string.Format("<h1>Age: {0}</h1>", i)).ToList();
|
|
19 var templates = Enumerable.Repeat(template, 10).ToList();
|
|
20 var models = Enumerable.Range(1, 10).Select(i => new Person { Age = i });
|
|
21
|
|
22 var results = service.ParseMany(templates, models, null, null, true).ToList();
|
|
23
|
|
24 for (int i = 0; i < 10; i++)
|
|
25 {
|
|
26 Console.WriteLine(templates[i]);
|
|
27 Console.WriteLine(expected[i]);
|
|
28 Console.WriteLine(results[i]);
|
|
29 }
|
|
30 }
|
|
31
|
|
32 Console.ReadKey();
|
|
33 }
|
|
34 }
|
|
35
|
|
36 /// <summary>
|
|
37 /// Defines a person.
|
|
38 /// </summary>
|
|
39 [Serializable]
|
|
40 public class Person
|
|
41 {
|
|
42 #region Properties
|
|
43 /// <summary>
|
|
44 /// Gets or sets the age.
|
|
45 /// </summary>
|
|
46 public int Age { get; set; }
|
|
47
|
|
48 /// <summary>
|
|
49 /// Gets or sets the forename.
|
|
50 /// </summary>
|
|
51 public string Forename { get; set; }
|
|
52
|
|
53 /// <summary>
|
|
54 /// Gets or sets the surname.
|
|
55 /// </summary>
|
|
56 public string Surname { get; set; }
|
|
57 #endregion
|
|
58 }
|
|
59 }
|