Skip to content

Ten-James/DtoGenerator

Repository files navigation

Dto Generator

Stop writing boilerplate code for your DTOs. This package will generate them for you.

Read more in Our Docs

Example

...
using TenJames.DtoGenerator;
...


[GenerateDto(DtoType.All)]
class User 
{
    [MapTo(typeof(string), "src.ToString()")]
    [DtoVisibility(DtoType.AllRead | DtoType.Update)]
    public Guid Id { get; set; }
    
    public string Name { get; set; }
    
    [DtoIgnore]
    public string Password { get; set; }
    
}


// will generate the following DTOs

class UserReadDto
{
    [Required] public string Id { get; set; }
    [Required] public string Name { get; set; }
}

class UserReadDetailDto
{
    [Required] public string Id { get; set; }
    [Required] public string Name { get; set; }
}

class UserCreateDto
{
    [Required] public string Name { get; set; }
}

class UserUpdateDto
{
    [Required] public string Name { get; set; }
}

 

Attributes

Main usage ate defined with attrubutes. The following attributes are available:

  • GenerateDtoAttribute: Entry point for the generator. It will generate a DTO for the class where it is defined.
  • DtoIgnoreAttribute: Ignore a property from the DTO generation.
  • MapToAttribute: Mapping a property with function to the DTO (read and detail)
  • MapFromAttribute: Mapping a property with function from the DTO (write)

About

DTO generator library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published