Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4

- run: dotnet build --configuration Release

# Create the NuGet package in the folder from the environment variable NuGetDirectory
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}

# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
Expand All @@ -54,7 +56,7 @@ jobs:
uses: actions/setup-dotnet@v4

# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
Expand All @@ -67,7 +69,7 @@ jobs:
# If some rules are not applicable, you can disable them
# using the --excluded-rules or --excluded-rule-ids option
- name: Validate package
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg") --excluded-rules Symbols,IconMustBeSet,LicenseMustBeSet

run_test:
runs-on: ubuntu-latest
Expand All @@ -87,7 +89,7 @@ jobs:
needs: [ validate_nuget, run_test ]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
Expand Down
8 changes: 7 additions & 1 deletion DtoGenerator/DtoGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseUrl>https://github.com/Ten-James/DtoGenerator/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageId>james-dto-generator-library</PackageId>
<PackageId>TenJames.DtoGenerator</PackageId>
<Copyright>MIT</Copyright>
<PackageTags>Generator DTO WebApi </PackageTags>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\Release\DtoGenerator.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,66 @@

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

# Introduction

Since its generator library, and it works on compile time you have to set the output type, for the dependency,

```xml
<ProjectReference Include="TenJames.DtoGenerator" Version="x.x.x" OutputItemType="Analyzer" />
```

# Example

```csharp

[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)
Loading