Share via


Visual Studio: Generate typescript classes from C#

Introduction

When we're developing in asp.net core and we use Typescript for the frontend, it's quite often that you want your C# classes (DTO'S) converted to typescript classes.  It's frustrating that you have to rewrite it to typescript. We can use an extension in Visual Studio that automatically converts your c# class to a typescript class. 

What do we need?

  • Open visual studio 2017
  • Go to Extensions and updates 
  • Search for "TypescriptSyntaxPaste" and install that package. It could be that you have to restart your visual studio.

 

How to use

I recommend that you create a new typescript file (for example "dtoclasses.ts"). This file will have the converted c# classes.

For example, I will convert two C# classes to typescript. select and copy the classes you want to convert

 

You can edit the settings via Tools=>options=>TypescriptPaste. 

References

https://marketplace.visualstudio.com/items?itemName=NhaBuiDuc.TypescriptSyntaxPaste