RazorEngine 3.6.5.0

时间:2023-03-09 01:05:52
RazorEngine 3.6.5.0
public class Person
{
public string Name
{
get;
set;
}
public string Code
{
get;
set;
}
}
    var templateServiceConfiguration = new TemplateServiceConfiguration();
//templateServiceConfiguration.Namespaces.Add("System.Configuration"); var body = string.Empty; using (var service = RazorEngineService.Create(templateServiceConfiguration))
{
body = service.RunCompile(
@"Hello @Model.Name @Model.Code ,
welcome to RazorEngine!","hello1",
typeof(Person),new Person(){Name="aaaa",Code=""});
Console.WriteLine(body);

Console.WriteLine(service.RunCompile("hello1",typeof(Person),new Person(){Name="bbbb",Code=""}));
}

输出

Hello aaaa 111 , 
welcome to RazorEngine!
Hello bbbb 222 , 
welcome to RazorEngine!