Skip to content

Converts C# classes and enums into TypeScript interfaces and enums.

Notifications You must be signed in to change notification settings

srmagura/ITI.TypeScriptDtoGenerator

Repository files navigation

ITI.TypeScriptDtoGenerator

Converts C# classes and enums into TypeScript interfaces and enums. Based on reflection.

Example usage:

internal class Program
{
    internal static void Main()
    {
        var outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TypeScript");

        if (!Directory.Exists(outputPath))
            Directory.CreateDirectory(outputPath);

        var enums = new List<Type>
        {
            typeof(ServiceType)
        };

        var dtos = new List<Type>
        {
            typeof(CustomerOrderDto),
            typeof(VendorOrderDto),
            typeof(UserDto),
            typeof(CustomerUserDto),
        };

        foreach (var @enum in enums)
        {
            TypeScriptDtoGenerator.GenerateEnum(@enum, outputPath);
        }
        Console.WriteLine("Generated TypeScript enums.");

        var imports = "import { EmailAddressDto } from './HandwrittenDtos'\n";

        TypeScriptDtoGenerator.GenerateDtos(dtos, enums, imports, outputPath);
        Console.WriteLine("Generated TypeScript DTOs.");

        TypeScriptDtoGenerator.GenerateIndex(outputPath);
        Console.WriteLine("Generated TypeScript DTO index.");
    }
}

Publishing

  1. Install https://github.com/microsoft/artifacts-credprovider

  2. Update the version number the ITI.TypeScriptDtoGenerator.csproj file.

  3. In PowerShell run

    ./Publish-NuGetPackage.ps1 x.x.x

    where x.x.x is the version number.

About

Converts C# classes and enums into TypeScript interfaces and enums.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published