Generate enums matching your C# enums.
Comes with generators for TypeScript.
EnumGenie is a nuget! Crazy, I know.
dotnet add package EnumGenie.TypeScript
See the wiki
See EnumGenie.Sample
project for a ...umm... sample. Crazy.
using EnumGenie.Filters;
using EnumGenie.Sample.Enums;
using EnumGenie.Sources;
using EnumGenie.Transforms;
using EnumGenie.TypeScript;
using EnumGenie.Writers;
namespace EnumGenie.Sample
{
public static class Program
{
public static void Main()
{
var genie = new EnumGenie()
.SourceFrom.Assembly(typeof(Program).Assembly)
.FilterBy.Predicate(t => t != typeof(Ignored))
.TransformBy.RenamingEnum(def => def.Name.Replace("StripThisOut", ""))
.WriteTo.Console(cfg => cfg.TypeScript(ts => ts.Declaration().Description().Descriptor()))
.WriteTo.File("./TypeScript/enums.ts", cfg => cfg.TypeScript(ts => ts.Declaration().Description().Descriptor()));
genie.Write();
}
}
}
Ensure you are calling .Write()
at the end. This is where the work is done, the rest is just configuration.