CSharp2TS is a tool to generate TypeScript files for classes, enums and API endpoints. It consists of 2 parts:
- CSharp2TS.Core - A very lightweight nuget package containing the attributes to mark classes, enums and controllers for generation.
- CSharp2TS.CLI - A dotnet tool to convert the marked files to TypeScript interfaces, enums and api services
CSharp2TS.Core is a very lightweight package containing the attributes to mark classes, enums and controllers for generation. For more information see the CSharp2TS.Core Docs.
CSharp2TS.Core is available on NuGet.
dotnet add package CSharp2TS.Core --prerelease
[TSInterface]
public class TestModel {
...
}[TSEnum]
public enum TestEnum {
...
}[TSService]
[ApiController]
[Route("api/[controller]")]
public class TestController : ControllerBase {
...
}For more examples check out the docs.
CSharp2TS.CLI is a dotnet tool to generate TypeScript files from .NET assemblies which have classes, enums and controllers marked with the attributes in the Core package. It an be run via command line arguments or a config file. For more information see the CSharp2TS.CLI Docs.
CSharp2TS.Core is available as a dotnet tool. To install globally run:
dotnet tool install -g CSharp2TS.CLI --prerelease
The tool can be run via a config file. The config file can be created from the command line, check out the docs for more information.
csharp2ts -c C:\path_to_config.json
Or via command line arguments
csharp2ts --model-output-folder C:\models_output --model-assembly-path C:\models_assembly --file-casing camel
For more possible arguments, and help commands, check out the docs.
CSharp2TS uses the Mono.Cecil project to interrogate assemblies without loading them into the AppDomain