.NET To TypeScript

Keep your .NET services, classes, enums in sync with TypeScript

Chart explaining working of .NET to TypeScript

.NET to TypeScript

This library is a perfect tool for .NET (C#, VB.NET) integrations with a TypeScript frontend.

The library is an .exe that you can configure via an XML file. Add the .exe to the post-build actions of your main assembly and every time you modify your .NET code, the corresponding TypeScript code will be generated.

Our tool can:

  • Generate TypeScript viewmodels for all your .NET viewmodels
  • Generate TypeScript enums for all your .NET enums
  • Generate Service proxies for all your .NET services. Imports will automatically be added to the header of the TypeScript file referencing the viewmodels and enums that are used in the signature of your services.
  • When using Angular in combination with the angular-l10n library for localization, the l10nConfig file will be generated based on translations found in the database. The database must be accessible via ODBC, the SQL statements can be configured in the XML configuration file.

Price: $ 20,00/developer.

Contact us for a trial version and more information about the usage and integration. We can also help with the architecture of your .NET-to-Angular project(s).

Configuration

The tool is a command-line tool that is configured by an XML file. The path to the XML file passed as a parameter to the tool. The idea is to place the .exe somewhere on your filesystem and in the post-build event of your project, to call the tool with the path of the configuration XML.

A sample XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Settings>
  <!-- ADDITIONAL ASSEMBLIES -->
  <AdditionalAssembliesToLoad>
    <string>C:\Web\bin\Debug\net461\TRIS.Framework.dll</string>
    <string>C:\Web\bin\Debug\net461\Unity.Abstractions.dll</string>
  </AdditionalAssembliesToLoad>
  <!-- ENUMS -->
  <EnumAssemblyPath>C:\Web\bin\Debug\net461\QuantInvest.Screener.BL.dll</EnumAssemblyPath>
  <EnumsTargetTSPath>C:\ngscreener\src\app\viewmodels\enums.ts</EnumsTargetTSPath>
  <EnumAttribute>TypescriptEnumAttribute</EnumAttribute>
  <!-- VIEWMODELS -->
  <ViewmodelsAssemblyPath>C:\Web\bin\Debug\net461\QuantInvest.Screener.ViewModels.dll</ViewmodelsAssemblyPath>
  <ViewmodelInterfaceName>IViewModel</ViewmodelInterfaceName>
  <ViewmodelsTargetTSPath>C:\ngscreener\src\app\viewmodels\viewmodels.ts</ViewmodelsTargetTSPath>
  <ViewmodelsImports>
    <![CDATA[ 
    import { %enums% } from '../viewmodels/enums';
  ]]>
  </ViewmodelsImports>
  <!-- SERVICES -->
  <ServicesAssemblyPath>C:\Web\bin\Debug\net461\QuantInvest.Screener.BL.dll</ServicesAssemblyPath>
  <ServiceInterfaceName>IService</ServiceInterfaceName>
  <ServicesTargetTSPath>C:\ngscreener\src\app\services</ServicesTargetTSPath>
  <ServiceParameterTypeToIgnore>CallContext</ServiceParameterTypeToIgnore>
  <HiddenAttribute>HiddenAttribute</HiddenAttribute>
  <ServiceHeaderPre>@Injectable()</ServiceHeaderPre>
  <ServiceImports>
    <![CDATA[ 
    import { Injectable } from '@angular/core';
    import { Observable } from 'rxjs/Observable';
    import { DataService } from './data.service';
    import { %enums% } from '../viewmodels/enums';
    import { %viewmodels% } from '../viewmodels/viewmodels';
  ]]>
  </ServiceImports>
  <ServiceConstructor>
    <![CDATA[ 
    constructor(private dataService:DataService) {}
  ]]>
  </ServiceConstructor>
  <ServiceMethodBody>
    <![CDATA[ 
    return this.dataService.invokeServer('%servicetype%.%methodname%', [%parameterlist%]);
  ]]>
  </ServiceMethodBody>
  <ServiceReturnTypeWrapper>Observable</ServiceReturnTypeWrapper>
  <!-- TRANSLATIONS -->
  <TranslationsTargetTSPath>C:\Applications\Xcelans\ngxcelans\src\app\viewmodels\l10nconfig.ts</TranslationsTargetTSPath>
  <TranslationsConnectionString>DSN=Xcelans</TranslationsConnectionString>
  <TranslationsSQL>SELECT lang,code,text FROM translation WHERE serveronly=0</TranslationsSQL>
</Settings>

This settings file contains the following items:

  • AdditionalAssembliesToLoad: path(s) to additional assemblies that must be loaded by the tool, in order to recognize all referenced classes. When running the tool the first time, the dynamic loader might throw exceptions about classes that are not found.
  • EnumAssemblyPath: path to the assembly containing the enums to convert
  • EnumsTargetTSPath: path of the TypeScript file that must be generated, containing the enums
  • EnumAttribute: attribute decorating the enums (create a custom attribute and decorate your enums with the attribute, in order for the tool to know which enums to convert)
  • ViewmodelsAssemblyPath: path to the assembly containing the viewmodels to convert (can be the same one as the enums assembly)
  • ViewmodelInterfaceName: interface identifying the viewmodels (create an interface and let all classes that must be treated as a viewmodel implement that interface)
  • ViewmodelsTargetTSPath: path of the TypeScript file that must be generated, containing the viewmodels
  • ViewmodelsImports: imports to add to the top of the viewmodels file. When using enums, an import instruction pointing to the enums file must be added.
    Use the code %enums% in the import statement as a placeholder: the tool will replace it with the enums that were actually used in the viewmodels.
  • ServicesAssemblyPath: path to the assembly containing the services to convert
  • ServiceInterfaceName: interface identifying the services (create an interface and let all classes that must be treated as a service implement that interface)
  • ServicesTargetTSPath: path to the folder that must contain the TypeScript files. For services, each service is contained in its own TypeScript file.
  • ServiceParameterTypeToIgnore: (optional) if the service methods have a parameter that must be ignored when translating the signature to TypeScript, you can specify it here. For example: when using Dependency Injection containers, it is possible that parameters are injected into the .NET method, but that these must not be part of the TypeScript signature.
  • HiddenAttribute: (optional) an attribute that describes which methods of the services must not be converted. Note that only public methods are converted, but you might want to indicate that some methods should not be converted, even though they are public.
  • ServiceHeaderPre: directive (or other code) that must be added before the class declaration. For example: @Injectable when using Angular.
  • ServiceImports: imports to add to the header of each service file.
    Use the code %enums% in the import statement as a placeholder: the tool will replace it with the enums that were actually used in the service.
    Use the code %viewmodels% in the import statement as a placeholder: the tool will replace it with the viewmodels that were actually used in the service.
  • ServiceConstructor: specific constructor to use in the service. Can be used to inject the class that will execute the data communication with the server
  • ServiceMethodBody: body of the methods of the service, that execute the actual call to the .NET service.
    Use the %servicetype% placeholder for the name of the .NET service class.
    Use the %methodname% placeholder for the name of the method in the .NET service class.
    Use the %parameterlist% placeholder for the list of parameters that are passed to the service.
  • ServiceReturnTypeWrapper: (optional) wrapper to use around the return type, for example Observable.
  • TranslationsTargetTSPath: path of the TypeScript file that must be generated, containing the l10nConfig class
  • TranslationsConnectionString: ODBC connection string to the database containing the translations
  • TranslationsSQL: SQL statement to fetch the translations. The result must always consist of 3 columns, containing in order: the language code, the translation code and the translated text.