ATK.Command.CsToTsGenerator
1.1.9
dotnet add package ATK.Command.CsToTsGenerator --version 1.1.9
NuGet\Install-Package ATK.Command.CsToTsGenerator -Version 1.1.9
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ATK.Command.CsToTsGenerator" Version="1.1.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ATK.Command.CsToTsGenerator" Version="1.1.9" />
<PackageReference Include="ATK.Command.CsToTsGenerator" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ATK.Command.CsToTsGenerator --version 1.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ATK.Command.CsToTsGenerator, 1.1.9"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ATK.Command.CsToTsGenerator@1.1.9
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ATK.Command.CsToTsGenerator&version=1.1.9
#tool nuget:?package=ATK.Command.CsToTsGenerator&version=1.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ATK.Command.CsToTsGenerator - Technical Documentation
Code generator for automatic generation of TypeScript types from C# types using .NET Reflection.
Requirements
- .NET 10.0
- Microsoft.CodeAnalysis 5.0.0
- System.CodeDom 10.0.1
Entry Point
using ATK.Command.CsToTsGenerator;
var generator = new Generator();
var tsGenerator = generator.TypeScript();
The class Generator is the central entry point:
Generator.TypeScript()→ InstantiatesTypeScriptGeneratorTypeScriptGeneratororchestrates the entire generation process
Generation Modes
SeparatedFiles - Each type in separate file
- One file per type
- Barrel export via
index.ts - Automatic directory clearing with flag
- Template:
Templates/SeparatedFiles/ - Classes:
SeparatedFilesGenerator,SeparatedFilesGeneratorWithMetaData,SeparatedFilesGeneratorWithRenderedTypes
OneFile - All types in one file
- All types in a single file
- Compact output
- Classes:
OneFileGenerator,OneFileGeneratorWithMetaData
Core Components
| Component | Description |
|---|---|
| Generator | Entry point, creates TypeScriptGenerator |
| TypeScriptGenerator | Orchestrates the generation process |
| SeparatedFilesGenerator | Generates separate TS files per type |
| OneFileGenerator | Generates all types into one TS file |
| TypeDependencyResolver | Recursively resolves type dependencies |
| TypeNameResolver | Converts C# names to TypeScript names |
| GeneratorType | Represents a C# type with metadata |
| GeneratorMember | Represents a property/field of a type |
Type Mapping
| C# | TypeScript |
|---|---|
int, long, short, byte |
number |
decimal, float, double |
number |
bool |
boolean |
string |
string |
DateTime, DateOnly |
string |
Enum |
enum |
List<T>, IEnumerable<T> |
T[] |
Dictionary<K, V> |
{ [key: K]: V } |
Nullable<T>, T? |
T \| null |
Guid |
string |
Template Engine
T4 Text Templates in Templates/:
SeparatedFiles/ComplexTypes/- Class/Record generationSeparatedFiles/Commands/- Command interfaceSeparatedFiles/Enums/- Enum generationSeparatedFiles/TypeScriptImports/- Import statementsSeparatedFiles/CodeGenerationWarning/- Generation header
API
SeparatedFilesGenerator
using ATK.Command.CsToTsGenerator;
var generator = new Generator();
var tsGenerator = generator.TypeScript();
var builtFiles = tsGenerator
.SeparatedFiles()
.SetInterfaceFilter(typeof(IRequestCommand))
.SetReturnTypeOfCommands(typeof(Response))
.SetRequestCommandInterfaceNameForGeneratedCommands("ICommand")
.AddRangeOfCommandTypesToGenerate(commandTypes)
.AddRangeOfExtraTypesToGenerate(dtoTypes)
.GenerateMetadata()
.GenerateTypeScript()
.Build();
builtFiles.Save(clearDestinationFolder: true);
OneFileGenerator
using ATK.Command.CsToTsGenerator;
var generator = new Generator();
var tsGenerator = generator.TypeScript();
var builtFile = tsGenerator
.OneFile()
.SetInterfaceFilter(typeof(IRequestCommand))
.SetReturnTypeOfCommands(typeof(Response))
.SetRequestCommandInterfaceNameForGeneratedCommands("ICommand")
.AddRangeOfCommandTypesToGenerate(commandTypes)
.AddRangeOfExtraTypesToGenerate(dtoTypes)
.GenerateMetadata()
.GenerateTypeScript()
.Build("output/api-types.ts");
builtFile.Save();
Data Models
| Class | Purpose |
|---|---|
GeneratorType |
C# type with metadata |
GeneratorMember |
Property/field of a type |
GeneratorTypeKind |
Classification (Class, Enum, Interface, Record) |
FileMetadata |
Output folder and metadata |
BuildFile |
Generated TypeScript file |
BuildedSeparatedFiles |
Collection of generated files |
Filter and Configuration
SetInterfaceFilter
- Only types implementing this interface
- Type selection for commands
SetReturnTypeOfCommands
- Response type for generated commands
- Default:
Response,ApiResponse
AddRangeOfCommandTypesToGenerate
- Select command types
- Converted to TypeScript interfaces
AddRangeOfExtraTypesToGenerate
- Add DTOs and other types
Type Classification
GeneratorTypeKind Enum:
Class- Regular classesInterface- InterfacesRecord- Record typesEnum- EnumerationsStruct- Structure types
Testing
Test projects in src/ATK.Command.CsToTsGenerator.Tests:
GeneratorTypeTests- Type recognitionClassGeneratorTypeTests- Class generationOneFileGeneratorTests- OneFile modeSeparatedFilesGeneratorTests- SeparatedFiles modeInheritanceTests- Inheritance handlingTypeDependencyResolverTests- Dependency resolutionTypeNameResolverTests- Name resolution
Build & NuGet
Build:
dotnet build
dotnet test
Package:
- ATK.Command.CsToTsGenerator
- Repository: https://github.com/a-t-k/ATK.Command.CsToTsGenerator
- License: LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.CodeAnalysis (>= 5.0.0)
- Microsoft.CodeAnalysis.Common (>= 5.0.0)
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
- System.CodeDom (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.9 | 119 | 4/18/2026 |