Introducing RazorSharpener
Introduction Sharpener: a person or device that makes something sharp (Cambridge Dictionary). RazorSharpener is a Razor compiler and renderer. It can load a .razor file and compile it into a .NET class that implements IComponent , the base interface for Razor components . This can be used, for example, to build a template engine, as Razor allows us to combine contents and code. Usage RazorSharpener is composed of just two classes: RazorCompiler : used to compile a .razor source file ( Razor component ) into a .NET class RazorRenderer : renders a Razor component type into a string Razor Compiler To compile a .razor file is very simple: var compiler = new RazorCompiler(); var asm = compiler.Compile("RenderMessage.razor"); As you can see, the Compile method takes a file from the current folder and produces an assembly, which is how .NET "wraps" generated code. If there is any compilation error, an exception is thrown. The generated assembly will...