Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myblindy/FastAutoMapper
The aim of this project is to provide compile-time support for auto-mapping by using source generation.
https://github.com/myblindy/FastAutoMapper
automapper efficiency source-generation
Last synced: about 1 month ago
JSON representation
The aim of this project is to provide compile-time support for auto-mapping by using source generation.
- Host: GitHub
- URL: https://github.com/myblindy/FastAutoMapper
- Owner: myblindy
- License: mit
- Created: 2021-08-24T16:06:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T17:19:58.000Z (over 2 years ago)
- Last Synced: 2024-08-01T22:43:56.962Z (4 months ago)
- Topics: automapper, efficiency, source-generation
- Language: C#
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - FastAutoMapper
README
[![publish to nuget](https://github.com/myblindy/FastAutoMapper/actions/workflows/nuget.yml/badge.svg)](https://github.com/myblindy/FastAutoMapper/actions/workflows/nuget.yml)
[![NuGet](http://img.shields.io/nuget/v/MB.FastAutoMapper.svg)](https://www.nuget.org/packages/MB.FastAutoMapper/) [![NuGet Downloads](http://img.shields.io/nuget/dt/MB.FastAutoMapper.svg)](https://www.nuget.org/packages/MB.FastAutoMapper/)# MB.FastAutoMapper
The aim of this project is to provide compile-time support for auto-mapping by using source generation. The ubiquitous AutoMapper instead builds the mapping code at run-time.
One of the benefits of this approach, besides paying the mapping cost at compile-time instead of run-time everytime, is that any mapping errors are also caught at compile time due to the strict type-safety of C#.
The code is pretty simple to use, simply reference the NuGet package `MB.FastAutoMapper` and write something like this:
```C#
using FastAutoMapper;class Src
{
public string Text { get; set; }
public float[] Color { get; set; }
}class Dst
{
public string Text { get; set; }
public Vector3 Color { get; set; }
}// first declare the mapper class, make sure it is a partial type
partial class Mapper : FastAutoMapperBase { }// then declare your instance
var mapper = new Mapper();// define the maps you need, including any conversions with `ForMember`
mapper.CreateMap()
.ForMember(x => x.Color, x => new Vector3(x.Color[0], x.Color[1], x.Color[2]));
// and map your instances
var dst = mapper.Map(new Src { Text = "meep", Color = new[] { .1f, .5f, 1f } });
```