AutoDto 2.1.0

dotnet add package AutoDto --version 2.1.0
NuGet\Install-Package AutoDto -Version 2.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoDto" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoDto --version 2.1.0
#r "nuget: AutoDto, 2.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AutoDto as a Cake Addin
#addin nuget:?package=AutoDto&version=2.1.0

// Install AutoDto as a Cake Tool
#tool nuget:?package=AutoDto&version=2.1.0

AutoDto

This tool allows to auto create DTO model from BL model in compile time.

It supports different strategies for relations, such as ReplaceToIdProperty, AddIdProperty and ReplaceToDtoProperty

Setup

To use AutoDto, first install the NuGet package:

dotnet add package AutoDto
  • Declare partial DTO type like public partial SomeDto {}
  • Add attribute [DtoFrom(typeof(SomeBlType))]
  • Build project

Full simple setup:

[DtoFrom(typeof(SomeBlType))]
public partial SomeDto {}

AutoDto tool will generate partial SomeDto class with all public properties from SomeBlType.

Relation Strategies

Relation strategy means what to do with relation property during generating DTO.

Supported strategies:

  • None
  • ReplaceToIdProperty
  • AddIdProperty
  • ReplaceToDtoProperty

Usage

Set strategy in [DtoFrom] attribute after BL type.

[DtoFrom(typeof(SomeBlType), RelationStrategy.AddIdProperty)]
public partial SomeDto {}

If not specified - RelationStrategy.None will be used

None

DTO will have property on BL type

ReplaceToIdProperty

If BL relation property has Id property: DTO will have only RelationPropNameId property of BL relation Id prop type. If BlType has relation with array or enumerable - generated name will be RelationPropNameIds

❗ If no Id found in relation entity - result will be same as with None strategy

AddIdProperty

DTO will have relation type property and Id property is found

ReplaceToDtoProperty

Try find DTO, generated for RelationType and replace to RelationTypeDto.

❗ If many DTOs exists for RelationType - use [MainDto] attribute to mark which one should be used in ReplaceToDtoProperty

Ignore properties

To avoid some properties from BlType, use [DtoIgnore] attribute:

[DtoFrom(typeof(SomeBlType), RelationStrategy.AddIdProperty)]
[DtoIgnore(nameof(SomeBlType.PropName1), nameof(SomeBlType.PropName2))]
public partial SomeDto {}

Options

Options can be set only in .editorconfig.

❗ All options are applied once, after first generator running (mostly after open project).

Generator running

Generator is based on IIncrementalGenerator. Generator is running on every class declaration change event (on every change that affects class structure). To avoid performance issues, it is used debouncer for collecting all events to regenerate classes. By default debounce time is 500 ms. After some time debouncer will collect execution statistic and rebalance timer.

Any user can turn off debouncer, set initial time ets by setting options in .editorconfig.

Supported options:

  • auto_dto.debounce.enabled - true/false - use debounce or always run generation for every event
  • auto_dto.debounce.interval - int - in milliseconds - set initial debounce interval
  • auto_dto.debounce.auto_rebalance_enabled - true/false - allow auto timer change or not.

Default values:

  • auto_dto.debounce.enabled = true
  • auto_dto.debounce.interval = 500
  • auto_dto.debounce.auto_rebalance_enabled = true

⚠️ Debouncer can be turned off and switched to every request generating.

Logging

Logger is disabled by default. If any issues with generator - enable logger, set folder path for logs and set logging level.

Supported options:

  • auto_dto.logger.folder_path - string - path to folder where logs will be generated
  • auto_dto.logger.enabled - true/false
  • auto_dto.logger.log_level - Serilog log levels. See LogEventLevel

Default values:

  • auto_dto.logger.folder_path = Try get value from build_property.projectdir. If cannot - Path.Combine(Environment.CurrentDirectory, "Logs") is using
  • auto_dto.logger.enabled = false
  • auto_dto.logger.log_level = Warning
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 746 6/1/2023
2.0.1 127 5/4/2023
2.0.0 156 4/26/2023
2.0.0-beta-2 124 4/24/2023
2.0.0-beta 125 4/24/2023
1.0.8 179 4/18/2023
1.0.7 160 4/18/2023
1.0.6 135 4/18/2023
1.0.5 157 4/18/2023
1.0.4 150 4/18/2023
1.0.3 176 4/18/2023
1.0.2 172 4/18/2023
1.0.1 145 4/18/2023
1.0.0 153 4/18/2023