MTT 0.7.2

dotnet add package MTT --version 0.7.2
NuGet\Install-Package MTT -Version 0.7.2
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="MTT" Version="0.7.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MTT --version 0.7.2
#r "nuget: MTT, 0.7.2"
#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 MTT as a Cake Addin
#addin nuget:?package=MTT&version=0.7.2

// Install MTT as a Cake Tool
#tool nuget:?package=MTT&version=0.7.2

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. This means its great for .Net Core and VS Code.

Install

Using dotnet CLI:

dotnet add package MTT

dotnet restore

Then in .csproj add a Target.

Options

WorkingDirectory is the input directory of the c# dtos (seperate multiple directories with ';')

ConvertDirectory is the output directory of the ts interfaces

AutoGeneratedTag (default true) show "/* Auto Generated */" at the top of every file. If set to false then no tags are generated

EnumValues (default int enums) if set to Strings, generates typescript string enums

PathStyle (default is folders stay the same and files become camelCase) if set to Kebab, changes the file and directory names to kebab-case.

PropertyStyle (default is CamelCase) if set to PascalCase, changes the properties to PascalCase.

Example

.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MTT" Version="0.7.2"/>
  </ItemGroup>

  <Target Name="Convert" BeforeTargets="PrepareForBuild">
    <ConvertMain WorkingDirectory="Resources/" ConvertDirectory="models/"/>
  </Target>

</Project>

Vehicle.cs

using System.Collections.Generic;
using Example.Resources.Parts;
using Example.Resources.Parts.Unit;

namespace Example.Resources.Vehicles
{
    public abstract class Vehicle : Entity 
    {
        public int Year { get; set; }
        public string Make { get; set; }
        public string Model { get; set; }
        public int? Mileage;
        public Dictionary<string, Units> Options { get; set; }
        public VehicleState Condition { get; set; }  // this is an enum of type int
        public virtual ICollection<Part> Parts { get; set; }
        public IList<Part> SpareParts { get; set; } = new List<Part>();
    }
}

vehicle.ts

/* Auto Generated */

import { Entity } from "./../entity";
import { Units } from "./../Parts/Unit/units";
import { VehicleState } from "./vehicleState";
import { Part } from "./../Parts/part";

export interface Vehicle extends Entity {
    year: number;
    make: string;
    model: string;
    mileage?: number;
    options: Partial<Record<string, Units>>;
    condition: VehicleState;
    parts: Part[];
    spareParts: Part[];
}

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
  • IList
  • Enum
  • Optional
  • virtual
  • abstract
  • Dictionary
  • IDictionary
  • Guid

Notes

If a Convert Directory is supplied, it will be deleted everytime script is ran and will be remade

Comments like // are ignored in c# files. Comments like /* */ could cause undefined behavior.

Tested on Windows 10, macOS Big Sur, and Ubuntu 18.04

Follows the case and naming conventions of each language.

Thanks to natemcmaster this project really helped me out!

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .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 30,451 8/15/2021
0.7.1 16,781 6/25/2021
0.7.0 3,951 4/5/2021
0.6.5 28,771 2/16/2020
0.6.3 1,747 11/17/2019
0.6.1 2,055 8/8/2019
0.6.0 806 8/5/2019
0.5.9 758 7/24/2019
0.5.8 809 7/11/2019
0.5.7 2,846 5/31/2019
0.5.6 844 4/24/2019
0.5.5 1,211 4/7/2019
0.5.4 29,054 10/18/2018
0.5.3 1,441 9/8/2018
0.5.2 973 9/8/2018
0.5.1 1,014 9/8/2018
0.5.0 1,047 9/8/2018
0.4.7 1,347 8/6/2018
0.4.6 1,242 7/9/2018
0.4.5 1,098 6/21/2018
0.4.4 2,456 6/14/2018
0.4.3 1,367 4/13/2018
0.4.1 1,235 4/12/2018
0.4.0 1,255 4/11/2018
0.3.3 1,174 3/16/2018
0.3.2 1,249 3/9/2018
0.3.1 1,474 3/6/2018
0.3.0 1,550 3/5/2018
0.2.3 1,072 2/22/2018
0.2.2 1,228 2/11/2018
0.2.1 1,285 2/10/2018
0.2.0 1,204 2/10/2018
0.1.6 1,207 2/8/2018
0.1.5 1,243 2/8/2018
0.1.4 1,190 2/8/2018
0.1.1 1,206 2/2/2018
0.1.0 1,122 2/2/2018