RSCG – Weave
| name | Weave |
| nuget | https://www.nuget.org/packages/Weave/ |
| link | https://github.com/otac0n/Weave |
| author | John Gietzen |
Scriban like generator
This is how you can use Weave .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <None Remove="MyDataT.weave" /> </ItemGroup> <ItemGroup> <PackageReference Include="Weave" Version="2.1.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup> <ItemGroup> <WeaveTemplate Include="MyDataT.weave"> </WeaveTemplate> </ItemGroup> <PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> </PropertyGroup> </Project>
The code that you will use is
using WeaveDemo;
Person p = new()
{
FirstName = "Andrei",LastName = "Ignat"
};
MyProject.Templates.RenderFizzBuzz(p,Console.Out);
StringWriter sw = new();
MyProject.Templates.RenderFizzBuzz(p,sw);
Console.WriteLine("---------------------------");
Console.WriteLine(sw.ToString());
namespace WeaveDemo;
internal class Person
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string FullName() => $"{FirstName} {LastName}";
}
The code that is generated is
// -----------------------------------------------------------------------
// <auto-generated>
// This code was generated by Weave 2.1.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// -----------------------------------------------------------------------
namespace
#line 1 "..\..\..\MyDataT.weave"
MyProject
#line default
{
using System;
using System.IO;
partial class
Templates
{
[System.CodeDom.Compiler.GeneratedCode("Weave","2.1.0.0")]
public
static void
#line 2 "..\..\..\MyDataT.weave"
RenderFizzBuzz
#line default
(
#line 3 "..\..\..\MyDataT.weave"
WeaveDemo.Person
#line default
model,TextWriter writer,string indentation = null)
{
var __originalIndentation = indentation = indentation ?? string.Empty;
writer.Write(indentation);
writer.Write("I will write p.FullName();");
writer.WriteLine();
writer.WriteLine();
writer.Write(indentation);
writer.Write(
#line 7 "..\..\..\MyDataT.weave"
model.FullName()
#line default
);
writer.WriteLine();
}
}
}
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Weave
Leave a Reply