Skip to content

Anotate typescript models with dataannotations validators and community toolkit mvvm attributes #203

@CastelloBrancoTecnologia

Description

Is there possible ? If not can you help me to implement it ?

Add typescripts decorators to generated typescript. Also support for private class fields.

using System.ComponentModel.DataAnnotations;
using CommunityToolkit.Mvvm;
using CommunityToolkit.Mvvm.ComponentModel;

[ExportTsClass]
public partial class ProductDto : ObservableValidator
{
    [ObservableProperty]
    [Required (ErrorMessage="Price is required")]
    [Range(1, 999, ErrorMessage="price must be in the range [1, 999].")]
    private decimal _price;

    [ObservableProperty]
    private string[] _tags;
}

generated class

export class ProductDto extends ObservableValidator
{
    @Required ("Price is required")
    @Range(1, 999, "price must be in the range [1, 999].")
    private _price: number;

    private _tags: string[];
}

Only genarate c# attributes that inherits from ValidatorAttribute to typescript decorators. All others attributes will be ignored. ErrorMessage attribute property will be translated to msg typescript decorator parameter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions