Ziv.MTT 0.6.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ziv.MTT --version 0.6.3                
NuGet\Install-Package Ziv.MTT -Version 0.6.3                
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="Ziv.MTT" Version="0.6.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ziv.MTT --version 0.6.3                
#r "nuget: Ziv.MTT, 0.6.3"                
#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 Ziv.MTT as a Cake Addin
#addin nuget:?package=Ziv.MTT&version=0.6.3

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

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

ConvertDirectory is the output directory of the ts interfaces

AutoGeneratedTag (default true) show "/* Auto Generated */" at the top of every file

EnumValues if set to Strings, generates typescript string enums instead of the default enums with numeric values which precisely reflect the C# enums

PathStyle if set to Kebeb, changes the file and directory names to kebeb-case. If it isn't set, the default behaviour applies which leaves the directory names as they are in the working directory and change the file names to camelCase.

Example

.csproj

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MTT" Version="0.6.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
    {
        // this is a top level comment
        public int Year { get; set; }
        public string Make { get; set; }
        public string Model { get; set; }
        public int? Mileage;
        public VehicleState Condition { get; set; }  // this is an enum of type int
        public virtual ICollection<Part> Parts { get; set; }
    }
}

vehicle.ts

/* Auto Generated */

import { Entity } from "../entity"
import { VehicleState } from "./vehicleState"
import { Part } from "../Parts/part"

export interface Vehicle extends Entity {
    year: number;
    make: string;
    model: string;
    mileage?: number;
    condition: VehicleState;
    parts: 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
  • Enum
  • Optional
  • virtual
  • abstract

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 Mojave, 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

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
0.6.14 3,152 9/21/2023
0.6.13 226 9/13/2023
0.6.12 200 9/13/2023
0.6.11 6,722 5/27/2021
0.6.10 523 12/11/2020
0.6.9 392 12/11/2020
0.6.8 600 9/1/2020
0.6.7 484 6/12/2020
0.6.6 440 5/17/2020
0.6.3 584 10/8/2019
0.6.2 478 10/8/2019