[NuGet]: Transplator

This is a Nuget that it is what Razor should have been. It is a Roslyn Source Code Generator that transforms template into code.

Link: https://www.nuget.org/packages/Transplator 

Site: https://github.com/atifaziz/Transplator

What it does:  Takes a template and generates source code for outputting anything inside.

Usage:

Somewhere in the csproj:

<ItemGroup>
   <CompilerVisibleProperty Include=”DebugTransplator” />
   <CompilerVisibleItemMetadata Include=”AdditionalFiles” MetadataName=”SourceItemType” />
   <CompilerVisibleItemMetadata Include=”AdditionalFiles” MetadataName=”Name” />
   <AdditionalFiles Include=”ASM.txt” SourceItemType=”Transplate” KeepMetadata=”Name” />

</ItemGroup>

Somewhere in a .cs file

var response = new ASMTemplate().Render();

And the template

partial class ASMTemplate
{
     StringBuilder sb = new StringBuilder();
     public void WriteText(string text)
     {
         sb.AppendLine(text);
     }
     public void WriteValue(int text)
     {
         sb.AppendLine(“”+text);
     }  
     public void WriteValue(int? text)
     {
         if(text != null)
             sb.AppendLine(“” + text);
     }
     public void WriteValue(DateTime text)
     {
         sb.AppendLine(text.ToString(“yyyy MMMM dd HH:mm:ss”));
     }
     public void WriteValue(string text)
     {
         sb.AppendLine(text);
     }
     public string Render()
     {        
         this.RenderCore();
         return sb.ToString();
     }
}