From b73fab9733532e3b4f7d38a0d707020bf65a2b39 Mon Sep 17 00:00:00 2001 From: rafageist Date: Thu, 15 Aug 2024 20:09:01 -0300 Subject: [PATCH] update readme --- README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++-- example/README.md | 53 +---------------------------- 2 files changed, 85 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index fa99e04..cb8ab11 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,84 @@ -# cs-mapper-generator -Div CSharp Mapper Generator +# Div CSharp Mapper Generator + +The Div CSharp Mapper Generator is a powerful tool designed to automate the creation of mapping classes in C#. It simplifies the process of mapping between models, DTOs, and other classes by generating the necessary code based on a simple JSON configuration file. This tool supports bi-directional mapping by default, with the flexibility to extend and customize the generated mappers through inheritance. + +## Features + +- *Automatic Code Generation*: Generate C# mapping classes based on a JSON configuration file. +- *Bi-Directional Mapping*: Supports mapping in both directions between classes. +- *Object Property Handling*: Automatically maps object properties, allowing for deep copies rather than reference assignments. +- *Extensibility*: Easily extend and customize the generated mapping methods by inheriting from the generated classes. +- *Custom Logic*: Override default methods to implement custom mapping logic as needed. + +## Getting Started + +### Prerequisites + +- .NET SDK (version 7.0 or later) +- A project with the classes you wish to map + +### Installation + +You can either compile the Div CSharp Mapper Generator from source or download the precompiled binary from the GitHub releases page. + +### Usage + +1. Create a JSON Configuration File + +Create a mapper.json file in the root of your project. This file defines the mappings you wish to generate. + +```json +{ + "mappers": [ + { + "namespace": "Namespace.Of.Your.Mapper", + "mapper": "MapperClassNameToGenerate", + "outputFolder": "output/folder/of/generated/mapper", + "classPairs": [ + [ "Relative/Path/To/ModelClassX.cs", "Relative/Path/To/ModelClassX.cs" ] // clone + [ "Relative/Path/To/ModelClassA.cs", "Relative/Path/To/ModelClassB.cs" ] // map + ] + } + ] +} +``` + +- `namespace`: The namespace for the generated mapper class. +- `mapper`: The name of the mapper class to generate. +- `outputFolder`: The directory where the generated mapper file will be placed. +- `classPairs`: An array of class pairs to map. Identical class pairs will generate a cloning method. + +2. Run the Mapper Generator + +Execute the following command from the root of your project: + +```bash +$ path/to/div-cs-mapper-generator.exe path/to/mapper.json +``` + +This command will generate the mapping classes based on the configuration provided in mapper.json. + +3. Locate the Generated Files + +The generated files will be found in the output folder specified in the JSON configuration. + +### Extends and customization + +You can inherit the generated mapper class to override the generated methods or add new ones. + +```csharp +namespace Namespace.Of.Your.Mapper +{ + public class MapperClassNameToGenerate : MapperClassNameToGenerateBase + { + public override ModelClassB Map(ModelClassA model) + { + var result = base.Map(model); + + // Custom logic here + + return result; + } + } +} +``` diff --git a/example/README.md b/example/README.md index 14a6c44..6849012 100644 --- a/example/README.md +++ b/example/README.md @@ -2,55 +2,4 @@ ## Example project -This project is an example of how to use the Div CS Mapper Generator. - -### How to use - -1. Compile or download the Div CS Mapper Generator from GitHub. - -2. Create a `mapper.json` file in the root of the project with the following content: - -```json -{ - "mappers": [ - { - "namespace": "Namespace.Of.Your.Mapper", - "mapper": "MapperClassNameToGenerate", - "outputFolder": "output/folder/of/generated/mapper", - "classPairs": [ - [ "Relative/Path/To/ModelClassX.cs", "Relative/Path/To/ModelClassX.cs" ] // clone - [ "Relative/Path/To/ModelClassA.cs", "Relative/Path/To/ModelClassB.cs" ] // map - ] - } - ] -} -``` - -3. Run the following command in the root of the project: - -```bash -$ path/to/div-cs-mapper-generator.exe path/to/mapper.json -``` - -4. The generated files will be in the defined outputFolder - -### Extends and customization - -You can inherit the generated mapper class to override the generated methods or add new ones. - -```csharp -namespace Namespace.Of.Your.Mapper -{ - public class MapperClassNameToGenerate : MapperClassNameToGenerateBase - { - public override ModelClassB Map(ModelClassA model) - { - var result = base.Map(model); - - // Custom logic here - - return result; - } - } -} -``` +This project is an example of how to use the Div CS Mapper Generator. \ No newline at end of file