JP.Toolbox.CSharp.Typescript 2023.5.34

dotnet add package JP.Toolbox.CSharp.Typescript --version 2023.5.34                
NuGet\Install-Package JP.Toolbox.CSharp.Typescript -Version 2023.5.34                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JP.Toolbox.CSharp.Typescript" Version="2023.5.34" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JP.Toolbox.CSharp.Typescript --version 2023.5.34                
#r "nuget: JP.Toolbox.CSharp.Typescript, 2023.5.34"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JP.Toolbox.CSharp.Typescript as a Cake Addin
#addin nuget:?package=JP.Toolbox.CSharp.Typescript&version=2023.5.34

// Install JP.Toolbox.CSharp.Typescript as a Cake Tool
#tool nuget:?package=JP.Toolbox.CSharp.Typescript&version=2023.5.34                

Typescript

A tool for (transpiling, converting) C# Classes, Interfaces, Enums to Typescript

DISCLAIMER

This is a personal, in development project. It is not recommended to use this in any application.

Usage

var convereter = new Converter(outputDirectory);
convereter.AddClass(typeof(MyClass));
convereter.AddEnum(typeof(MyEnum));
convereter.AddInterface(typeof(IMyInterface));
convereter.Build();

Notes

  • Only supports public classes, interfaces, enums
  • If a Type is used but not added to the convereter, the convereter will throw an exception
  • In order for the Type to work with the convereter, you must use the corrent Attributes
  • Classes or Interfaces with same 'Name' or 'Filename' with throw an exception
  • Enums with same 'Name' or 'Filename' with throw an exception
  • NOTE** Enums will be exported as 'export enum'
  • As of now, the convereter support Lists, but not Dictionaries or Arrays

Attributes

The attributes are used to give the convereter more information about the class, interface or enum. They take two arguments that are mandatory, 'Name' and 'Filename'. The 'Name' is the name of the class, interface or enum.

  •   [TypescriptClassAttribute] : Used for classes
    
  •   [TypescriptInterfaceAttribute] : Used for interfaces
    
  •   [TypescriptEnumAttribute] : Used for enums
    
  •   [TypescriptGenericClassAttribute] : Used for generic classes
    

There is a special Attribute for enums [TypescriptEnumStringValue]. This attribute is used to give the enum values a string value, which is not possible in C#. The attribute takes one argument, 'Value', which is the string value of the enum value.

Attributes exambles and outputs

[TypescriptEnumAttribute("MyEnum", "my-enum")]
public enum MyDifferentEnum
{
	[TypescriptEnumStringValue("Value1")]
	Value1,
	[TypescriptEnumStringValue("Value2")]
	Value2
}

This will be exported as <u>'my-enum.enum.ts'</u> and will look like this:

export enum MyEnum {
	Value1 = "Value1",
	Value2 = "Value2"
}

The class :

[TypescriptClassAttribute("MyClass", "my-class")]
public class ThisNameDoesNotMater
{
	public string Name { get; set; } = "MyName";
	public int Age { get; set; } = 20;
}

This will be exported as <u>'my-class.class.ts'</u> and will look like this:

export class MyClass {
	Name: string = "MyName";
	Age: number = 20;
}

The class :

[TypescriptInterfaceAttribute("MyInterfaceClass", "my-interface-class")]
public class ThisNameDoesNotMater
{
	public string Name { get; set; } = "MyName";
	public int Age { get; set; } = 20;
}

This will be exported as <u>'my-interface-class.interface.ts'</u> and will look like this:

export interface MyInterfaceClass {
	Name: string;
	Age: number;
}

The interface :

[TypescriptInterfaceAttribute("MyInterface", "my-interface")]
public interface ThisNameDoesNotMater<T,Q,K>
{
	string Name { get; set; }
	int Age { get; set; }
}

This will be exported as <u>'my-interface.interface.ts'</u> and will look like this:

export interface MyInterface<T, Q, K> {
	Name: string;
	Age: number;
}

TODO List

- Add custom property name Attribute
- Add ingore property Attribute 
- Add support for Dictionaries
- Add support for Arrays
- Extensive testing

Changelog

2023.5.30

  • Classes now can be entered as Interfaces and as classes

2023.5.21

  • Removed Generic Classes support
  • Added support for Generic Interfaces
  • Fixed class output
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2023.5.34 158 5/31/2023
2023.5.30 143 5/31/2023
2023.5.25 139 5/30/2023
2023.5.3 135 5/29/2023