Single-class-per-file C# to TypeScript generator
Documentation: http://typegen.readthedocs.io
Running the following commands will create NuGet packages in the root directory (in this example for version 3.0.0):
.\update-version.ps1 3.0.0
.\publish.ps1
Add the TypeGen NuGet package to your project. The dotnet-typegen package can be used for a .NET tool.
Select the types to export to TypeScript:
// using attributes
[ExportTsClass]
public class ProductDto
{
public decimal Price { get; set; }
public string[] Tags { get; set; }
}
// or using a specification file (a "generation spec") created anywhere in your project
public class MyGenerationSpec : GenerationSpec
{
public MyGenerationSpec()
{
AddClass<ProductDto>();
}
}
tgconfig.json
directly in your project folder with the following content:{
"generationSpecs": ["MyGenerationSpec"]
}
TypeGen generate
or TypeGen -p "MyProjectName" generate
(depending on the current working directory of the PM Console) into the Package Manager Console (you might need to restart Visual Studio), or dotnet typegen generate
in the system console to use the .NET tool.After completing the above, a single TypeScript file (named product-dto.ts) should be generated in your project's root directory with the following content:
export class ProductDto {
price: number;
tags: string[];
}
The features include (full list of features is available in the documentation):