Giter Club home page Giter Club logo

dtogenerator's Introduction

DTOGenerator

Experimental zero code compile time DTO generator and mapper using Source Generators in C#.

Attributes

Attribute Description Notes
GenerateDto Add to class to generate DTO. If DTO name isn't supplied, by default DTOGenerator will create one called "classNameDTO". DTOGenerator can create unlimited amount of DTOs from the same class. Refer to example below.
ExcludeProperty Add to exclude property in DTO. You can supply a name of a DTO to only exclude in specific ones, else it will be excluded in all DTOs.
UseExistingDto Add to use an existing DTO for an object that is nested in another DTO. You can supply a specific DTO to use based off of.

Example

Screenshot Link Description
Station class Link This will create two DTOs "StationDTO" and "StationWithNoNameDTO". "Name" will be excluded in "StationWithNoNameDTO" and "Level" will be excluded in all.
WeatherForcast class Link This will create two DTOs "WeatherForecastDTO" and "TestingWeather". "TemperatureF" will be excluded in all DTOs. "Summary" will be excluded in the "TestingWeather" DTO. "StationWithNoNameDTO" will be used in "TestingWeather" but in "WeatherForecastDTO" it will use the default "StationDTO".

Example of generated classes from above

public class StationDTO
{
  public string Name { get; set; }
  
  public StationDTO Map(Station instance)
  {
    Name = instance.Name;
    return this;
   }
}
public class StationWithNoNameDTO
{
  public StationWithNoNameDTO Map(Station instance)
  {
    return this;
   }
}
public class WeatherForecastDTO
{
  public DateTime Date { get; set; }
  public int TemperatureC { get; set; }
  public string Summary { get; set; }
  public StationDTO Station { get; set; }
  
  public WeatherForecastDTO Map(WeatherForecast instance)
  {
    Date = instance.Date;
    TemperatureC = instance.TemperatureC;
    Summary = instance.Summary;
    Station = new StationDTO().Map(instance.Station);
    return this;
   }
}

dtogenerator's People

Contributors

zeshan321 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.