Peled-Zohar / AutoEntityGenerator

A Visual Studio extension that simplifies the process of generating Data Transfer Objects (DTOs) and mapping extensions based on existing domain entity classes.
MIT License
1 stars 1 forks source link

AutoEntityGenerator

AutoEntityGenerator is a Visual Studio extension that simplifies the process of generating Data Transfer Objects (DTOs) and mapping extensions based on existing domain entity classes. This extension helps developers quickly create and maintain supporting classes, enhancing productivity and reducing manual coding errors.

Features

Note

Currently, only types with parameterless constructors are supported for mapping generation.
If the model doesn't have a parameterless constructor, the generated mapping extension will not compile.
In future versions, I plan to support entities without parameterless constructors by allowing users to include the properties that correspond to the constructor parameters.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Installation

   From Visual Studio Marketplace

   You can install the AutoEntityGenerator extension directly from the Visual Studio Marketplace.
   Simply navigate to the extension's page and click on "Install" to add it to your Visual Studio environment.

   Manual Installation

   Alternatively, you can install the extension by downloading the .vsix file from the latest release.
   Once downloaded, double-click the .vsix file and follow the instructions in the VSIX installer to complete the installation.

Target platforms

Currently only supported target is visual studio 2022 community version.
I plan to expand that in the future, but I will need to test each target platform before adding them to the supported target list.

Usage

  1. Open your project in Visual Studio.
  2. Open the file containing your domain entity.
  3. Press ctrl. or altenter to open the light bulb / screwdriver menu on the class (or record) declaration of the domain entity you want to generate DTOs for.
  4. Select 🔧 Generate DTO and mapping 🛠️ from the context menu.
  5. Configure the generation options in the UI dialog that appears.
  6. Click OK to generate the DTOs and mapping extensions.

Configuration

AutoEntityGenerator allows you to configure various aspects of the code generation process, including:

Example

Suppose you have a domain entity class Product:

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}

Using AutoEntityGenerator, you can generate the following Request DTO and mapping method with just a few mouse clicks:

public partial class CreateProductRequest
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}

public static partial class CreateProductRequestDtoMappingExtensions
{
    public static Product ToProduct(this CreateProductRequest request)
    {
        return new Product
        {
            Id = request.Id,
            Name = request.Name,
            Price = request.Price
        };
    }
}

Contributing

We welcome contributions to improve AutoEntityGenerator! If you encounter any bugs or have feature requests, please open an issue on the GitHub repository.

Steps to Contribute

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes.
  4. Push the branch to your forked repository.
  5. Open a pull request to the main repository.

Thank you for using AutoEntityGenerator! We hope it enhances your development experience by automating the creation of DTOs and mapping methods.