Coder Social home page Coder Social logo

typegen's Introduction

TypeGen

Single-class-per-file C# to TypeScript generator

โ˜• Buy me a coffee

Build status

Documentation: http://typegen.readthedocs.io

How to get

How to build

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

How to use

  1. Add the TypeGen NuGet package to your project. The dotnet-typegen package can be used for a .NET tool.

  2. 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>();
    }
}
  1. If you're using a generation spec, create a file named tgconfig.json directly in your project folder with the following content:
{
  "generationSpecs": ["MyGenerationSpec"]
}
  1. Build your project and type 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[];
}

Features

The features include (full list of features is available in the documentation):

  • generating TypeScript classes, interfaces and enums (single class per file)
  • generating barrel (index) files
  • support for collections
  • support for generic types
  • support for inheritance
  • customizable translation of naming conventions

typegen's People

Contributors

jburzynski avatar stephtr avatar sdamian avatar cs-net avatar dersia avatar bcrosnier avatar bergi9 avatar mispencer avatar rametta avatar allov avatar vsvirydau-cl avatar newdark90 avatar elwynelwyn avatar onliner10 avatar sidney-pauly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.