MTTRunner 1.0.28.7589

dotnet add package MTTRunner --version 1.0.28.7589
                    
NuGet\Install-Package MTTRunner -Version 1.0.28.7589
                    
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="MTTRunner" Version="1.0.28.7589" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MTTRunner" Version="1.0.28.7589" />
                    
Directory.Packages.props
<PackageReference Include="MTTRunner" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MTTRunner --version 1.0.28.7589
                    
#r "nuget: MTTRunner, 1.0.28.7589"
                    
#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.
#:package MTTRunner@1.0.28.7589
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MTTRunner&version=1.0.28.7589
                    
Install as a Cake Addin
#tool nuget:?package=MTTRunner&version=1.0.28.7589
                    
Install as a Cake Tool

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 MTTRunner

(The original package name is 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 (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.

Example

.csproj

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

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

  <ItemGroup>
    <PackageReference Include="MTT" Version="0.6.5"/>
  </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: Map<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 Mojave, and Ubuntu 18.04

Follows the case and naming conventions of each language.

Thanks to natemcmaster this project really helped me out!

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

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
1.0.28.7589 144 10/28/2024
1.0.27.7574 161 10/18/2024
1.0.24.7135 266 11/23/2023
1.0.23.6772 250 3/30/2023
1.0.22.6766 272 3/16/2023
1.0.21.6765 280 3/16/2023
1.0.20.6763 279 3/7/2023
1.0.19.6760 286 2/28/2023
1.0.18.6759 266 2/28/2023
1.0.17.6104 440 5/13/2021
1.0.16.6089 375 4/9/2021
1.0.15.6088 403 3/25/2021
1.0.14.6087 426 3/25/2021
1.0.13.6086 435 3/25/2021
1.0.12.6085 381 3/25/2021
1.0.10.6083 417 3/24/2021