using RazorEngine.Templating;
public static void Main()
var model = new MyModel{Name = "hello"};
string template = $"@using Test\nHello @Model.Name.WordCount(), welcome to RazorEngine!";
var result = Engine.Razor.RunCompile(template, "templateKey", typeof(MyModel), model);
Console.WriteLine(result);
Console.WriteLine(template.WordCount());
public static class MyExtensions
public static int WordCount(this String str)
return str.Split(new char[]{' ', '.', '?'}, StringSplitOptions.RemoveEmptyEntries).Length;