-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRazorTemplateEngine.cs
More file actions
89 lines (77 loc) · 3.04 KB
/
RazorTemplateEngine.cs
File metadata and controls
89 lines (77 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using RazorEngineCore;
using System;
using System.ComponentModel;
using System.Globalization;
namespace MbSoftLab.TemplateEngine.Core;
public class RazorTemplateEngine<T> : ITemplateEngine<T> where T : TemplateDataModel<T>
{
public string CloseingDelimiter { get { Console.WriteLine($"RazorTemplateEngine has no {nameof(CloseingDelimiter)}"); return ""; } set => Console.WriteLine($"Can not set {nameof(CloseingDelimiter)} for RazorTemplateEngine"); }
ITemplateEngineConfig<T> _config;
public ITemplateEngineConfig<T> Config
{
get => _config;
set
{
_config = value;
this.NullStringValue = _config.NullStringValue;
this.OpeningDelimiter = _config.OpeningDelimiter;
this.CloseingDelimiter = _config.CloseingDelimiter;
this.TemplateDataModel = _config.TemplateDataModel;
this.TemplateString = _config.TemplateString;
this.CultureInfo = _config.CultureInfo;
}
}
public CultureInfo CultureInfo { get { Console.WriteLine($"{nameof(RazorTemplateEngine<T>)} can not maipulate {nameof(CultureInfo)}"); return null; } set => Console.WriteLine($"{nameof(RazorTemplateEngine<T>)} can not maipulate {nameof(CultureInfo)}"); }
public string NullStringValue
{
get => "String.Empty";
set { Console.WriteLine(new WarningException($"{nameof(RazorTemplateEngine<T>)} can not maipulate {nameof(NullStringValue)}").Message); }
}
public string OpeningDelimiter
{
get
{
Console.WriteLine(new WarningException($"RazorTemplateEngine has no {nameof(OpeningDelimiter)}").Message);
return "";
}
set
{
Console.WriteLine(new WarningException($"Can not set {nameof(OpeningDelimiter)} for RazorTemplateEngine").Message);
}
}
public T TemplateDataModel { get; set; }
public string TemplateString { get; set; }
IRazorEngine razorEngine;
public RazorTemplateEngine(IRazorEngine razorEngine)
{
this.razorEngine = razorEngine;
}
public RazorTemplateEngine()
{
razorEngine = new RazorEngine();
}
public RazorTemplateEngine(T dataModel, string templateString)
{
razorEngine = new RazorEngine();
TemplateDataModel = dataModel;
TemplateString = templateString;
}
public string CreateStringFromTemplate(string csHtmlTemplate = null)
{
TemplateString = csHtmlTemplate ?? TemplateString;
IRazorEngineCompiledTemplate template = razorEngine.Compile(TemplateString);
string result = template.Run(TemplateDataModel);
return result;
}
public string CreateStringFromTemplate(T templateDataModel)
{
TemplateDataModel = templateDataModel;
return CreateStringFromTemplate();
}
public string CreateStringFromTemplate(T templateDataModel, string csHtmlTemplate)
{
TemplateDataModel = templateDataModel;
TemplateString = csHtmlTemplate;
return CreateStringFromTemplate();
}
}