MTT 0.4.1
See the version list below for details.
dotnet add package MTT --version 0.4.1
NuGet\Install-Package MTT -Version 0.4.1
<PackageReference Include="MTT" Version="0.4.1" />
paket add MTT --version 0.4.1
#r "nuget: MTT, 0.4.1"
// Install MTT as a Cake Addin #addin nuget:?package=MTT&version=0.4.1 // Install MTT as a Cake Tool #tool nuget:?package=MTT&version=0.4.1
C# DTOs to Typescript Interfaces
MTT generates TypeScript interfaces from .NET DTOs. It implements most major features of the current TypeScript specification. This utility could be preferred over some others as it is completely independent of your IDE or workflow, because it uses a MSBUILD task and converts the code directly from the source.
Install
Using dotnet CLI:
dotnet add package MTT
dotnet restore
Then in .csproj add a Target.
Options
WorkingDirectory is the input directory of the cs dtos
ConvertDirectory is the output directory of the ts interfaces
AutoGeneratedTag (default true) show "/* Auto Generated */" at the top of every file
Example
.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MTT" Version="0.4.1"/>
</ItemGroup>
<Target Name="Convert" BeforeTargets="PrepareForBuild">
<ConvertMain WorkingDirectory="Resources/" ConvertDirectory="models/"/>
</Target>
</Project>
Vehicle.cs
using System.Collections.Generic;
using Example.Resources.Parts;
namespace Example.Resources.Vehicles
{
public class Vehicle : Entity
{
public VehicleMake Make { get; set; }
public VehicleModel Model { get; set; }
public VehicleYear Year { get; set; }
public VehicleState Condition { get; set; } //this is an enum<int>
public string Description { get; set; }
public ICollection<VehiclePart> Parts { get; set; }
}
}
vehicle.ts
/* Auto Generated */
import { Entity } from "../entity"
import { VehicleMake } from "./vehicleMake"
import { VehicleModel } from "./vehicleModel"
import { VehicleYear } from "./vehicleYear"
import { VehicleState } from "./vehicleState"
import { VehiclePart } from "../Parts/vehiclePart"
export interface Vehicle extends Entity {
make: VehicleMake;
model: VehicleModel;
year: VehicleYear;
condition: VehicleState;
description: string;
parts: VehiclePart[];
}
Types
It correctly converts the following C# types to the equivalent typescript:
- bool
- byte
- decimal
- double
- float
- int
- uint
- long
- sbyte
- short
- string
- ulong
- ushort
- Boolean
- Byte
- Char
- DateTime
- Decimal
- Double
- Int16
- Int32
- Int64
- SByte
- UInt16
- UInt32
- UInt64
- Array
- Collection
- Enumerbale
- IEnumerable
- ICollection
- Enum
Notes
If a Convert Directory is supplied, it will be deleted everytime script is ran and will be remade
Matches the directory structure of the dto's, however it only checks 1 lower directory from Working Directory
Since javascript does not have an enum, but typescript does, only enums of type int will be supported for simplicity.
Read more about typescript enums here
Tested on Windows 10 and macOS High Sierra
Follows the case and naming conventions of each language.
Thanks to natemcmaster this project really helped me out!
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.7.1
- No dependencies.
-
.NETStandard 1.6
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MTT:
Package | Downloads |
---|---|
BindOpen.Messages.IO.Dtos
A package to easily deal with feeds. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.7.2 | 41,047 | 8/15/2021 |
0.7.1 | 17,027 | 6/25/2021 |
0.7.0 | 4,066 | 4/5/2021 |
0.6.5 | 31,702 | 2/16/2020 |
0.6.3 | 1,780 | 11/17/2019 |
0.6.1 | 2,084 | 8/8/2019 |
0.6.0 | 839 | 8/5/2019 |
0.5.9 | 792 | 7/24/2019 |
0.5.8 | 840 | 7/11/2019 |
0.5.7 | 3,050 | 5/31/2019 |
0.5.6 | 880 | 4/24/2019 |
0.5.5 | 1,247 | 4/7/2019 |
0.5.4 | 30,354 | 10/18/2018 |
0.5.3 | 1,475 | 9/8/2018 |
0.5.2 | 1,010 | 9/8/2018 |
0.5.1 | 1,045 | 9/8/2018 |
0.5.0 | 1,081 | 9/8/2018 |
0.4.7 | 1,383 | 8/6/2018 |
0.4.6 | 1,269 | 7/9/2018 |
0.4.5 | 1,132 | 6/21/2018 |
0.4.4 | 2,484 | 6/14/2018 |
0.4.3 | 1,398 | 4/13/2018 |
0.4.1 | 1,267 | 4/12/2018 |
0.4.0 | 1,288 | 4/11/2018 |
0.3.3 | 1,207 | 3/16/2018 |
0.3.2 | 1,289 | 3/9/2018 |
0.3.1 | 1,496 | 3/6/2018 |
0.3.0 | 1,580 | 3/5/2018 |
0.2.3 | 1,106 | 2/22/2018 |
0.2.2 | 1,256 | 2/11/2018 |
0.2.1 | 1,312 | 2/10/2018 |
0.2.0 | 1,232 | 2/10/2018 |
0.1.6 | 1,243 | 2/8/2018 |
0.1.5 | 1,281 | 2/8/2018 |
0.1.4 | 1,225 | 2/8/2018 |
0.1.1 | 1,240 | 2/2/2018 |
0.1.0 | 1,155 | 2/2/2018 |