Well, after searching the code, I found some useful examples (https://github.com/Antaris/RazorEngine/blob/master/src/source/RazorEngine.Hosts.Console/Program.cs) and found out that if you include
using RazorEngine.Templating;
at the top of your class, you can use some extension methods (https://github.com/Antaris/RazorEngine/blob/master/src/source/RazorEngine.Core/Templating/RazorEngineServiceExtensions.cs) that will help you.
Painless template compilation :
Engine.Razor.Compile(templatePath, "templateNameInTheCache", modelType);
Template Parsing :
Engine.Razor.Run("templateNameInTheCache", modelType, model);
And now you can do both at the same time !
string myParsedTemplate = Engine.Razor.RunCompile(templatePath, "templateNameInTheCache", null, model)
Which is the equivalent of doing this
Engine.Razor.AddTemplate("templateNameInTheCache", TemplateLoader.GetTemplate(templatePath));
Engine.Razor.Compile("templateNameInTheCache", modelType);
string finallyThisIsMyParsedTemplate = Engine.Razor.Run("templateNameInTheCache", modelType);
Please note that I'm currently testing this, but it seems to work fine.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…