Skip to content

Box-Of-Hats/ts-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

}

About

Convert typescript interfaces into to C# classes

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •