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
- Host: GitHub
- URL: https://github.com/ten-james/dtogenerator
- Owner: Ten-James
- License: mit
- Created: 2025-03-09T12:10:37.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-10T20:42:13.000Z (over 1 year ago)
- Last Synced: 2025-11-27T12:25:17.338Z (7 months ago)
- Topics: csharp, dotnet, dtos, generator, nuget, package
- Language: PowerShell
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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)