Skip to content

This package helps to convert C# Poco to typescript class and interface.

Notifications You must be signed in to change notification settings

YuvrajSagarRana/csharp-to-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

csharp-to-typescript

csharp-to-typescript is most flexible and easy to use npm package which doesn't use any third party library for conversion. This package have various options while converting C# Poco to typescript.

Dependencies

install

npm i csharp-to-typescript

How to use

  1. After installation, import the package.
var { CsharpToTs, getConfiguration } = require("csharp-to-typescript");
  1. Use CsharpToTs to convert your source code a. Method one give your source code as string:
const sourceCodeInString =   `public class Address
{
  public int Id {get; set;}
  public string Street { get; set; }
  public string City { get; set; }
}`

var outputTypescript = CsharpToTs(sourceCodeInString, getConfiguration());
console.log(outputTypescript);

Output is

export class Address
{
  Id: number;
  Street: string;
  City: string;
}

Advance Conversion Setting

By default,

  1. Access modifier are false.
  2. Method type to signature.
  3. Change Class to Interface is false.
var preserveModifier = false;
var methodType = "signature"; // other options are 'lambda' or 'controller'
var changeToInterface = false;

You can change like this:

  1. If you want to preserve accessfier
var preserveModifier = true;
var methodType = "signature"; // other options are 'lambda' or 'controller'
var changeToInterface = false;

const sourceCodeInString =   `public class Address
{
  public int Id {get; set;}
  public string Street { get; set; }
  public string City { get; set; }
}`

var outputTypescript = CsharpToTs(sourceCodeInString, getConfiguration(preserveModifier, methodType,changeToInterface ));
console.log(outputTypescript);

Output:

export class Address
{
  public Id: number;
  public Street: string;
  public City: string;
}
  1. Change class to interface:
var preserveModifier = false;
var methodType = "signature"; // other options are 'lambda' or 'controller'
var changeToInterface = true;

const sourceCodeInString =   `public class Address
{
  public int Id {get; set;}
  public string Street { get; set; }
  public string City { get; set; }
}`

var outputTypescript = CsharpToTs(sourceCodeInString, getConfiguration(preserveModifier, methodType,changeToInterface ));
console.log(outputTypescript);

Output:

export interface Address
{
  Id: number;
  Street: string;
  City: string;
}

You can also customized all the variable at once.

var preserveModifier = true;
var methodType = "controller"; // other options are 'lambda' or 'controller'
var changeToInterface = true;

License

MIT

About

This package helps to convert C# Poco to typescript class and interface.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published