An open API service indexing awesome lists of open source software.

https://github.com/ten-james/dtogenerator

DTO generator library
https://github.com/ten-james/dtogenerator

csharp dotnet dtos generator nuget package

Last synced: 5 months ago
JSON representation

DTO generator library

Awesome Lists containing this project

README

          

# Dto Generator

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

[Read more in Our Docs](https://ten-james.github.io/DtoGenerator/)

# Example

```csharp

...
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)