Skip to content

zmjack/TypeSharp

Repository files navigation

TypeSharp

C# model to the TypeScript model compiler.


How to use

Use annotation

  1. Set TypeScriptModel annotation to class:

    [TypeScriptModel(Namespace = "App")]
    public class Cls
    {
         public int Value { get; set; }
    }

    If TypeScriptModelAttribute not set. the namespace is same as the class Namespace

  2. Compile to TypeScript code:

    var builder = new TypeScriptModelBuilder();
    builder.CacheType<Cls>();
    var tscode = builderCompile();

Specified directly

  1. Define class:

    public class Cls
    {
         public int Value { get; set; }
    }
  2. Compile to TypeScript code:

    var builder = new TypeScriptModelBuilder();
    builder.CacheType<Cls>();
    var tscode = builder.Compile();

    If TypeScriptModelAttribute not set. the namespace is same as the class Namespace


Output result

/* Generated by TypeSharp v0.4.0.0 */

declare namespace App {
    interface Cls {
        value? : number;
    }
}