eQuantic.Mapper.Generator
1.6.0
See the version list below for details.
dotnet add package eQuantic.Mapper.Generator --version 1.6.0
NuGet\Install-Package eQuantic.Mapper.Generator -Version 1.6.0
<PackageReference Include="eQuantic.Mapper.Generator" Version="1.6.0" />
<PackageVersion Include="eQuantic.Mapper.Generator" Version="1.6.0" />
<PackageReference Include="eQuantic.Mapper.Generator" />
paket add eQuantic.Mapper.Generator --version 1.6.0
#r "nuget: eQuantic.Mapper.Generator, 1.6.0"
#:package eQuantic.Mapper.Generator@1.6.0
#addin nuget:?package=eQuantic.Mapper.Generator&version=1.6.0
#tool nuget:?package=eQuantic.Mapper.Generator&version=1.6.0
eQuantic.Mapper Library
The eQuantic Mapper provides all the implementation needed to use the Mapper Pattern
To install eQuantic.Mapper, run the following command in the Package Manager Console
Install-Package eQuantic.Mapper
If you choose to use generated mappers, install the Generator package below
Install-Package eQuantic.Mapper.Generator
Example of implementation
The models
public class ExampleA
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Date { get; set; } = string.Empty;
}
public class ExampleB
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public DateTime Date { get; set; }
[MapFrom(typeof(ExampleA), nameof(ExampleA.Id))]
public string Code { get; set; } = string.Empty;
}
The mapper
public class ExampleMapper : IMapper<ExampleA, ExampleB>
{
public ExampleB? Map(ExampleA? source)
{
return Map(source, new ExampleB());
}
public ExampleB? Map(ExampleA? source, ExampleB? destination)
{
if (source == null)
{
return null;
}
if (destination == null)
{
return Map(source);
}
destination.Id = source.Id;
destination.Name = source.Name;
destination.Date = source.Date;
return destination;
}
}
The mapper with context
public class ExampleContext
{
public string Code { get; set; }
}
public class ExampleMapper : IMapper<ExampleA, ExampleB, ExampleContext>
{
public ExampleContext Context { get; set; }
public ExampleB? Map(ExampleA? source)
{
return Map(source, new ExampleB());
}
public ExampleB? Map(ExampleA? source, ExampleB? destination)
{
if (source == null)
{
return null;
}
if (destination == null)
{
return Map(source);
}
destination.Id = source.Id;
destination.Name = source.Name;
destination.Date = source.Date;
if(!string.IsNullOrEmpty(Context.Code))
{
destination.Code = Context.Code;
}
return destination;
}
}
Auto-Generated Code
If you want that the mapper to be auto-generated, you need to use the MapperAttribute and partial definition into the class mapper
[Mapper(typeof(ExampleA), typeof(ExampleB))]
public partial class ExampleMapper : IMapper
{
}
or
[Mapper(typeof(ExampleA), typeof(ExampleB))]
public partial class AsyncExampleMapper : IAsyncMapper
{
}
The application
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMappers();
var app = builder.Build();
app.MapGet("/", (IMapperFactory mapperFactory) =>
{
var mapper = mapperFactory.GetMapper<ExampleA, ExampleB>()!;
var exampleA = new ExampleA
{
Id = "1",
Name = "Test",
Date = "2023-01-01"
};
var exampleB = mapper.Map(exampleA);
return exampleB;
});
app.Run();
Manual customization
If you need customize the auto-generated mapper, just create delegations for OnBeforeMap or/and OnAfterMap events:
[Mapper(typeof(ExampleA), typeof(ExampleB))]
public partial class ExampleMapper : IMapper
{
partial void AfterConstructor()
{
OnAfterMap += (s, e) =>
{
if(e.Source.Name == "Test")
{
e.Destination.Name = "Empty";
}
};
}
}
If you need to modify the generated constructor, just set OmitConstructor on attribute and create the new one:
[Mapper(typeof(ExampleA), typeof(ExampleB), OmitConstructor = true)]
public partial class ExampleMapper : IMapper
{
public ExampleMapper(IMapperFactory mapperFactory)
{
MapperFactory = mapperFactory;
OnAfterMap += (s, e) =>
{
if(e.Source.Name == "Test")
{
e.Destination.Name = "Empty";
}
};
}
}
Debugging
Inside MapperGenerator on Initialize method use:
#if DEBUG
SpinWait.SpinUntil(() => Debugger.IsAttached);
#endif
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
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.0.0 | 213 | 8/29/2025 |
| 1.9.0 | 197 | 7/8/2025 |
| 1.8.0 | 193 | 7/6/2025 |
| 1.7.0 | 289 | 5/29/2025 |
| 1.6.3 | 212 | 5/27/2025 |
| 1.6.2 | 190 | 5/26/2025 |
| 1.6.1 | 194 | 5/10/2025 |
| 1.6.0 | 240 | 2/23/2025 |
| 1.5.1 | 294 | 1/20/2025 |
| 1.5.0 | 157 | 1/20/2025 |
| 1.4.0 | 1,006 | 9/18/2024 |
| 1.3.6 | 410 | 7/23/2024 |
| 1.3.5 | 176 | 7/22/2024 |
| 1.3.4 | 176 | 7/22/2024 |
| 1.3.3 | 166 | 7/22/2024 |
| 1.3.2 | 217 | 7/20/2024 |
| 1.3.1 | 184 | 7/15/2024 |
| 1.3.0 | 216 | 7/1/2024 |
| 1.2.8 | 215 | 6/28/2024 |
| 1.2.7 | 203 | 6/28/2024 |
| 1.2.6 | 188 | 6/28/2024 |
| 1.2.5 | 196 | 6/28/2024 |
| 1.2.4 | 434 | 5/5/2024 |
| 1.2.3 | 206 | 5/4/2024 |
| 1.2.2 | 193 | 5/4/2024 |
| 1.2.1 | 299 | 5/3/2024 |
| 1.2.0 | 254 | 5/3/2024 |
| 1.1.9 | 315 | 4/23/2024 |
| 1.1.8 | 210 | 4/23/2024 |
| 1.1.7 | 186 | 4/23/2024 |
| 1.1.6 | 294 | 4/23/2024 |
| 1.1.5 | 644 | 11/18/2023 |
| 1.1.4 | 603 | 8/2/2023 |
| 1.1.3 | 378 | 7/15/2023 |
| 1.1.2 | 358 | 7/15/2023 |
| 1.1.1 | 255 | 7/15/2023 |
| 1.1.0 | 447 | 5/18/2023 |
| 1.0.0 | 315 | 1/8/2023 |
DTOs mapping without reflection