如何用RazorEngineService替换TemplateService?

时间:2015-12-14 11:47:35

标签: c# razor html-email

我有如下所示的代码,我想用更新的RazorEngineService替换TemplateService。你能告诉我如何在我的代码中替换它吗?

PS:我已经检查了https://antaris.github.io/RazorEngine/但是当我尝试将代码重构为RazorEngineService时,我遇到了一些例外。

public class ReminderEmail
{
    string templateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmailTemplates");
    string templateFilePath;
    ReminderEmailModel model;

    public ReminderEmail(ReminderEmailModel model)
    {
        this.model = model;
        try
        {
            templateFilePath = Path.Combine(templateFolderPath, "ReminderEmail.cshtml");
        }
        catch (FileNotFoundException e)
        {
            //TODO: log file not found here
        }
    }


    public string GetHtmlBody()
    {
        var templateService = new TemplateService();
        var emailHtmlBody = templateService.Parse(File.ReadAllText(templateFilePath), model, null, null);
        return emailHtmlBody;
    }
}

0 个答案:

没有答案