关闭。这个问题是opinion-based .它目前不接受答案。
想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它.
8年前关闭。
Improve this question
有人可以解释一下有什么区别,优点/缺点
RazorEngine
RazorTemplates
RazorMachine
我需要选择一个来生成电子邮件。这些要求很常见:快速、易于使用。似乎它们都具有我需要的所有功能,但由于我是 Razor 新手,我不太清楚哪个更好。
谢谢。
最佳答案
我自己尝试了所有 3 个库,发现了一些差异。
dynamic
类型。可以使用预编译的模板。 至于我,我选择了 RazorEngine。另外这里是如何使用这些库的代码:
RazorEngine
string html = Razor.Parse(templateContent, model, templatePath);
Razor 模板 if (!_templatesCache.ContainsKey(templatePath))
{
var compiledTemplate = Template.Compile(templateContent);
_templatesCache.Add(templatePath, compiledTemplate);
}
string html = _templatesCache[templatePath].Render(model);
Razor 机 private readonly Lazy<RazorMachine> _lazyRazorMachine =
new Lazy<RazorMachine>(() => new RazorMachine());
//...
var rm = _lazyRazorMachine.Value;
string html = rm.ExecuteContent(templateContent, model, null, true).Result;
还有一些性能测试,在同一个模板上对每个库进行了 2 次测试,它们的性能都差不多,没有太大的区别:RazorEngine - 1731 ms, 0.1 ms
RazorTemplates - 1753 ms, 0.1 ms
RazorMachine - 1608 ms, 0.1 ms
关于.net - RazorEngine vs RazorTemplates vs RazorMachine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18253822/