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. AutoEntityGenerator logs to event log, meaning you can view the logs using windows Event Viewer, under "Windows logs" -> "Application" with the source "AutoEntityGenerator".
- Automatically generates DTOs from domain entity classes or records.
- Creates mapping extension methods to convert between domain entities and DTOs.
- Supports generating code in the same folder or a new folder.
- User-friendly UI for configuring generation options.
- Seamless integration with Visual Studio.
- Supports all kinds of DTOs.
- Generates DTOs as records when the C# version allows it, or as classes for older versions.
- All generated classes are partial, allowing users to add custom code while still maintaining the ability to re-generate if needed.
- Supports generic types and generic constraints.
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.
This project is licensed under the MIT License - see the LICENSE file for details.
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.
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.
Supported targets are visual studio 2022 - Community, Professinal and Enterprise editions.
- Open your project in Visual Studio.
- Open the file containing your domain entity.
- 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.
- Select 🔧 Generate DTO and mapping 🛠️ from the context menu.
- Configure the generation options in the UI dialog that appears.
- Click OK to generate the DTOs and mapping extensions.
AutoEntityGenerator allows you to configure various aspects of the code generation process, including:
- The target folder (and namespace) for the generated classes.
- The properties required in the generated DTO.
- The generated DTO name
- The generated file name
- The generated mapping direction (from DTO to Model or from Model to DTO)
AutoEntityGenerator allows you to configure some default values for the extension:
- The minimum log level
- The default destination folder
- The default suffix for request and response DTOs
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
};
}
}
We welcome contributions to improve AutoEntityGenerator! If you encounter any bugs or have feature requests, please open an issue on the GitHub repository.
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes.
- Push the branch to your forked repository.
- 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.