Skip to content

saeedrahimi/ts-from-csmodels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate Typescript form C# models

This is a tool that consumes your C# domain models and types and creates TypeScript declaration files from them. There's other tools that does this but what makes this one different is that it internally uses Roslyn (the .NET compiler platform) to parse the source files, which removes the need to create and maintain our own parser.

NPM version

Dependencies

Install

$ npm install --save ts-from-csmodels

How to use

  1. Add a config file to your project that contains for example...
{
    "include": {
  
      "./src/output-directory": [ 
        "../../another-csharp-models/first/**/*.cs",
        "../../another-csharp-models/second/models.ts"
       ],
      "./src/another-output-directory": [ 
        "../../another-csharp-models/another/**/*.cs",
      ]  
  
    },
    "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": "ts-from-csmodels --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 © Saeed Rahimi

About

Generates typescript declarations from C# models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published