Convert C# Models, ViewModels and DTOs into their TypeScript equivalents using webapps, CLI Tool or VSCode extension. Links: https://marketplace.visualstudio.com/items?itemName=adrianwilczynski.csharp-to-typescript - https://csharptotypescript.azurewebsites.net - https://adrianwilczynski.github.io/CSharpToTypeScript/ - https://www.nuget.org/packages/CSharpToTypeScript.CLITool/
First of all, thanks for the work put in here 🎉
Just one nuance I came to notice when I wanted to use it in my project: In my codebase in C# I have two types (tracks and albums) which both can be in a list (as IDocuments). Both have the property type on which they both have a fixed name.
By this I can have a union-type in typescript but am able to determine by the property type which of them I have at hand, and the typescript compiler will narrow down the type. This is not possible if I want to use this repo to convert my C# classes to typescript, because it translates the property type to string.
Input
public interface IDocument : IDocument<int>
{ }
public interface IDocument<T>
{
T Id { get; set; }
string Type { get; }
}
public class Album : IDocument
{
public static string TypeName = "album";
public int Id { get; set; }
public IEnumerable<Track> Tracks { get; set; }
public string Type => TypeName;
}
public class Track : IDocument
{
public static string TypeName = "track";
public int Id { get; set; }
public int Length { get; set; }
public string Type => TypeName;
}
First of all, thanks for the work put in here 🎉
Just one nuance I came to notice when I wanted to use it in my project: In my codebase in C# I have two types (tracks and albums) which both can be in a list (as IDocuments). Both have the property
type
on which they both have a fixed name.By this I can have a union-type in typescript but am able to determine by the property
type
which of them I have at hand, and the typescript compiler will narrow down the type. This is not possible if I want to use this repo to convert my C# classes to typescript, because it translates the propertytype
tostring
.Input
Current output
Expected output
By the expected output, this typescript code would be valid: