RSCG – AutoDTO

RSCG – AutoDTO
 
 

name AutoDTO
nuget https://www.nuget.org/packages/AutoDTO/
link https://github.com/Ohorodnikov/AutoDto
author Ohorodnikov

Generate DTO classes from business/ef classes

 

This is how you can use AutoDTO .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoDto" Version="2.1.0" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using AutoDTODemo;

var d = new Department();
d.Name = "IT";
d.ID = 1;
d.Employees=new Employee[] { new Employee() };

var dto= new DepartmentDTO();
//it will be beneficial if it will have also a constructor
//for transfer properties
dto.Name = d.Name;
dto.ID = d.ID;


namespace AutoDTODemo;
public class Department
{
    public int ID { get; set; }
    public string? Name { get; set; }
    public Employee[]? Employees { get; set; }
}



using AutoDto.Setup;

namespace AutoDTODemo;

[DtoFrom(typeof(Department))]
[DtoIgnore(nameof(Department.Employees))]
public partial class DepartmentDTO { 
}


 

The code that is generated is

namespace AutoDTODemo;

public partial class DepartmentDTO
{
public System.Int32 ID { get; set; }
public System.String Name { get; set; }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/AutoDTO