-
Notifications
You must be signed in to change notification settings - Fork 3
uml4net.HandleBars.project
The uml4net.HandleBars project/library provides HandleBars helpers to support code generation. With Handlebars it is possible to use typical dot notitation to access properties of a class. But, functions and extension methods cannot be invoked this way. That's where the helpers come in. In Handlebars.NET, helpers are reusable methods or utilities used to simplify and extend the functionality of Handlebars templates.
For code generation helpers are used to add logic to a template or, when the algorithm used to determine which code to generate is more involved, helpers are use to write output using the Write or WriteSafeString methods.
All helpers shall all be placed in the root of the project and no folder structure shall be used.
Some examples to give some idea of how helpers are used:
Used to write a boolean value to the output. Generates either true or false:
public static class BooleanHelper
{
public static void RegisterBooleanHelper(this IHandlebars handlebars)
{
handlebars.RegisterHelper("Boolean.ToLowerCase", (writer, context, parameters) =>
{
if (parameters.Length != 1)
{
throw new HandlebarsException("{{#Boolean.ToLowerCase}} helper must have exactly one argument");
}
var value = (bool)parameters[0];
writer.WriteSafeString(value.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
});
}
}
Used to provide utilty methods to operate or query information about a Class. Typically extension methods are wrapped in HandleBars helpers.
The below helper returns all the Properties that belong to a Class. This includes the so-called owned attributes and all owned attributes of super classes and interfaces that the class implements.
public static class ClassHelper
{
public static void RegisterClassHelper(this IHandlebars handlebars)
{
handlebars.RegisterHelper("Class.QueryAllProperties", (context, _) =>
{
if (!(context.Value is IClass @class))
{
throw new ArgumentException("supposed to be IClass");
}
var properties = @class.QueryAllProperties().OrderBy(x => x.Name);
return properties;
});
}
}
copyright @ Starion Group S.A.