RegisterTemplate type error C# .Net Handlebars

The docs for this library seem straightforward enough, but attempting to register a partial throws a type conversion error:

string testname = "myName";
string testbody = @"my really simple test body";
Handlebars.RegisterTemplate(testname, testbody);

Argument 2: cannot convert from 'string' to 'System.Action<System.IO.TextWriter, object>'

Somewhat new to C# still, but this is almost identical to the example in the docs so I can't imagine that I've somehow miss-typed the testbody string.

Further research

Literally copy-pasting the example breaks the code. Looks like this may just be a crap library.

string partialSource = 
@"<strong>{{name}}</strong>";

Handlebars.RegisterTemplate("user", partialSource);

Argument 2: cannot convert from 'string' to 'System.Action<System.IO.TextWriter, object>'

Jon Skeet
people
quotationmark

The static Handlebars.RegisterTemplate(string, string) method was added in this commit on January 31st 2017. The last NuGet release of Handlebars.Net was in October 2016 - so you don't have access to it yet.

Options:

  • Wait for it to be released on NuGet
  • Download and build locally from GitHub
  • Effectively work round it by doing what the new code does.

For the final option, I believe you should be able to replace this:

string testName = "myName";
string testBody = @"my really simple test body";
Handlebars.RegisterTemplate(testName, testBody);

with

var template = Handlebars.Compile(new StringReader(testBody));
Handlebars.Register(testName, template);

people

See more on this question at Stackoverflow