Skip to content

colinnuk/csharp-models-to-typescript

 
 

Repository files navigation

C# models to TypeScript

This is a tool that creates TypeScript files from your C# domain models, records, enums and types. There's other tools that does this but what makes this one different is that it internally uses Roslyn (the .NET compiler platform) to parse the source files, which removes the need to create and maintain our own parser.

NOte: Currently I havent pushed this to nuget, so you will have to fork the repo and build it yourself.

Install

dotnet tool install -g csharpmodelstotypescript

(Or install it locally if you prefer)

How to use

Create an options JSON file with the below format & drop it in the folder where you want to run the tool.

{
  "InputFolder": "C:\\path-to-folder",
  "OutputFolder": "C:\\path-to-folder",
  "LineEnding": "\n",
  "IndentSize": 2,
  "UseSemiColon": false,
  "UseSingleQuote": true
}

Only InputFolder & OutputFolder are required, the others are optional. Default values are as above.

Then run the tool with the below command

csharpmodelstotypescript csharptotypescript.json

This tool is easy to use and can be integrated into your build pipeline by adding the below XML to your .csproj file.

  <Target Name="csharptotypescript" AfterTargets="AfterBuild">
    <Exec Command="dotnet tool restore" />
    <Exec Command="dotnet csharptotypescript $(ProjectDir)csharptotypescript.json" />
  </Target>

License

Adapted from the below github profile MIT © Jonathan Svenheden

About

C# models to TypeScript

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%