Skip to content

JamesLoyd/csharp-models-to-typescript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# models to TypeScript

This is a soft fork of Jonathan Persson's csharp-models-to-typescript npm package. The main difference is that we do auto import of dependent classes and interfaces in csharp classes.

For example

public class MyExample: IExample
{
    public SomePropClass SomeValue {get; set; }
}

is translated into

import {IExample} from "./IExample"
import { SomePropClass } from "./SomePropClass";

export interface MyExample extends IExample {
    SomeValue: SomePropClass;
}

Dependencies

Install

$ npm install --save csharp-models-to-typescript

How to use

  1. Add a config file to your project that contains for example...
{
    "include": [
        "./models/**/*.cs",
        "./enums/**/*.cs"
    ],
    "exclude": [
        "./models/foo/bar.cs"
    ],
    "namespace": "Api",
    "output": "./models",
    "camelCase": false,
    "camelCaseEnums": false,
    "numericEnums": false,
    "stringLiteralTypesInsteadOfEnums": false,
    "customTypeTranslations": {
        "ProductName": "string",
        "ProductNumber": "string"
    }
}
  1. Add a npm script to your package.json that references your config file...
"scripts": {
    "generate-types": "csharp-models-to-typescript --config=your-config-file.json"
},
  1. Run the npm script generate-types and the output file specified in your config should be created and populated with your models.

License

MIT © Jonathan Persson, Armstrong DevTeam

About

C# models to TypeScript

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C# 55.1%
  • JavaScript 44.9%