ts-csharp
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

ts-csharp

Convert typescript interfaces or classes to csharp classes.

Example usage

import { convertInterfacesToCSharp } from "ts-csharp";

const myTypescriptClassString = `
interface MyTypescriptClass {
    propOne : any;
    propTwo : string;
    propThree : number[];
    propFour : boolean;
}

interface AnotherTypescriptClass {
    nestedObjectsInAList : MyTypescriptClass[];
    recursiveObject : AnotherTypescriptClass;
    isReallyCool : boolean;
}
`;

const myCsharpClass = convertInterfacesToCSharp(myTypescriptClassString);

console.log(myCsharpClass);

Generates the following code:

public class MyTypescriptClass {

    [JsonProperty("propOne")]
    public object PropOne;

    [JsonProperty("propTwo")]
    public string PropTwo;

    [JsonProperty("propThree")]
    public IEnumerable<int> PropThree;

    [JsonProperty("propFour")]
    public bool PropFour;

}

public class AnotherTypescriptClass {

    [JsonProperty("nestedObjectsInAList")]
    public IEnumerable<MyTypescriptClass> NestedObjectsInAList;

    [JsonProperty("recursiveObject")]
    public AnotherTypescriptClass RecursiveObject;

    [JsonProperty("isReallyCool")]
    public bool IsReallyCool;

}

Readme

Keywords

none

Package Sidebar

Install

npm i ts-csharp

Weekly Downloads

1

Version

0.3.3

License

ISC

Unpacked Size

5.66 kB

Total Files

3

Last publish

Collaborators

  • box-of-hats