Features

Angular services from ASP.NET controllers

Generates an Angular service with all required models from an ASP.NET controller

Clone C# classes to TypeScript

Converts a C# class from your project or any third-party-library to a TypeScript model

TypeScript strict support

Detects automatically when you are using strict mode in your frontend (or enable it via attribute) and produces compatible code

Supports DataAnnotations

Can handle some attributes from System.ComponentModel.DataAnnotations like Required or DefaultValue

Customizable

Change the output like you want, like prefer classes or interfaces, prefer properties or fields, rename, change or ignore types or properties or custom formatting and indenting

Extendable

Write easily your own plugin and have access to all Generator resources. We will support you by coding

Native Types

Converts each native type to an matching type

Complex Types

Also support complex types containing lists, arrays or dictionaries

Inheritance

Support complex class or interface trees of any length and skips unnecessary types

JSON file to C# class

Generates a C# class to load and save a JSON file with all necessary properties and sub-classes

Sqlite database to C# class or vice versa

Generates C# classes from a Sqlite database or generates a repository class, containing all required commands to create, read, update and delete records or initialize a database

More stuff

like generate Angular services from SignalR hubs, generate oData controllers, classes from OpenApi/Swagger, classes from XML or generate TSQL repositories and read models from MSSQL database

Clone your C# models to the frontend

Decorate your C# model with an attribute and generate a TypeScript clone.

TypeToRead.cs
// Decorate your model with an attribute from KY.Generator namespace

[GenerateAngularModel("Output/Models")]
public class TypeToRead
{
    public string StringProperty { get; set; }
    public int NumberProperty { get; set; }
}
type-to-read.ts
Live
// produces a TypeScript class

export class TypeToRead {
    public stringProperty: string;
    public numberProperty: number;

    public constructor(init?: Partial<TypeToRead>) {
        Object.assign(this, init);
    }
}

The output can be changed by various attributes like: GeneratePreferInterfaces, GenerateStrict, GenerateFieldsAsProperties, GeneratePropertiesAsFields and some more

See the full example on github External Link

Synchronize your Frontend with Backend

The Generator ensures that each change or breaking-change will be directly reflected into your frontend.

Like a ASP.NET controller changes a method name or return type. Some critical changes like incompatible return types will break your frontend and you are able to see the difference and handle it correctly. Some other changes like changed routes are fixed silently by the Generator.

Decorate your ASP.NET controller with an attribute and generates an Angular service with all required models

WeatherForecastController.cs
// Decorate your controller with an attribute from KY.Generator namespace

[GenerateAngularService("ClientApp\src\app\services", "ClientApp\src\app\models")]
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    ...
    
    [HttpGet]
    public IEnumerable<WeatherForecast> Get()
    {
       ...
    }
}
weather-forecast.service.ts
Live
// produces an Angular service and fixes some common issues like 'strings instead of Dates', or unexpected nulls
    
@Injectable({
    providedIn: "root"
})
export class WeatherForecastService {
    ...

    public get(httpOptions?: {}): Observable<WeatherForecast[]> {
        let subject = new Subject<WeatherForecast[]>();
        let url: string = this.serviceUrl + "/weatherforecast";
        this.http.get<WeatherForecast[]>(url, httpOptions).subscribe((result) => {
            if (result) {
                result.forEach((entry) => {
                    entry.date = this.convertToDate(entry.date);
                });
            }
            subject.next(this.fixUndefined(result));
            subject.complete();
        }, (error) => subject.error(error));
        return subject;
    }
    
    ...

The Generator also produces all required models

weather-forecast.ts
export class WeatherForecast {
    public date?: Date;
    public temperatureC?: number;
    public temperatureF?: number;
    public summary?: string;

    public constructor(init?: Partial<WeatherForecast>) {
        Object.assign(this, init);
    }
}

Like in the previous example the output can be manipulated by additional attributes (global for all controllers and models or per single controller)

See the full example on github External Link

or read the step by step guide here

Generate Angular Service from SignalR Hub

Decorate your SignalR hub with an attribute and the Generator produces you a fully working angular service and all required models

WeatherHub.cs
// Decorate your controller with an attribute from KY.Generator namespace

public interface IWeatherHub
{
    Task Updated(IList<WeatherForecast> forecast);
}

[GenerateAngularHub("\ClientApp\src\app\services", "\ClientApp\src\app\models")]
[GenerateWithRetry(true, 0, 0, 1000, 2000, 5000)]
public class WeatherHub : Hub<IWeatherHub>
{
    ...

    public void Fetch()
    {
        ...
    }
}
weather-hub.service.ts
Live
// produces an Angular service with all methods and events

@Injectable({
    providedIn: "root"
})
export class WeatherHubService {
    ...
    private readonly updatedSubject: Subject<WeatherForecast[]> = new Subject<WeatherForecast[]>();
    public readonly updated$: Observable<WeatherForecast[]> = this.updatedSubject.asObservable();

    ...

    // Send a "Fetch" message to the hub with the given parameters. Automatically connects to the hub.
    public fetch(): Observable<void> {
        let subject = new Subject<void>();
        this.connect().pipe(mergeMap(() => this.connection), take(1), mergeMap((connection) => connection.send("Fetch"))).subscribe(() => {
            subject.next();
            subject.complete();
        }, (error) => subject.error(error));
        return subject;
    }
}

See the full example on github External Link

Continue reading with Annotations Overview

Tags

Generate angular service from ASP.NET controllerGenerate angular service from SignalR hubGenerate TypeScript class from C# classGenerate C# class from JSONGenerate C# class from Sqlite databaseGenerate Sqlite database from C# class