Skip to content

A simple dotnet tool that generates TypeScript interfaces, enums, and API endpoint definitions from C# DTOs, enums, and controllers.

License

Notifications You must be signed in to change notification settings

ormesam/CSharp2TS

Repository files navigation

CSharp2TS

Build Deploy

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

NuGet Version

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.

Installation

CSharp2TS.Core is available on NuGet.

dotnet add package CSharp2TS.Core --prerelease

Example Usage

[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

NuGet Version

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.

Installation

CSharp2TS.Core is available as a dotnet tool. To install globally run:

dotnet tool install -g CSharp2TS.CLI --prerelease

Example Usage

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.

Under The Hood

CSharp2TS uses the Mono.Cecil project to interrogate assemblies without loading them into the AppDomain

About

A simple dotnet tool that generates TypeScript interfaces, enums, and API endpoint definitions from C# DTOs, enums, and controllers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •