Language: EN

mapster-mapeador-de-clases-de-alta-velocidad-para-net

Mapster, high-speed class mapper for .NET

Mapster is an Open Source library for mapping objects in .NET focused on ease of use and high efficiency.

Mapping objects is a common need in programming, and it forces the creation of a lot of repetitive and low-value-added code (boilerplate).

To make this process more enjoyable, there are many libraries, with the most popular probably being the well-known AutoMapper.

Mapster is an alternative that stands out for its ease of use, and its design focused on high speed and low memory consumption.

To use Mapster, we don’t need to create any kind of prior configuration. It works through extension methods, so mapping an entity to a new instance of another class is as simple as doing

var destObject = sourceObject.Adapt<Destination>();

Or, to map to an existing instance

sourceObject.Adapt(destObject);

That simple. One might think that this lack of configuration has a penalty in performance, but it is not so.

Mapster is extremely fast, while maintaining minimal memory consumption, even several orders of magnitude above alternatives like AutoMapper.

Of course, Mapster not only performs conversions between simple objects, but also collections, composite objects, or almost any situation we may need. It also has a large number of additional features, such as custom mappings, actions before and after mapping.

On the other hand, efficiency can be further improved by including https://github.com/dadhi/FastExpressionCompiler, reaching a performance very similar to that obtained with “hand-made” mapping.

As if all this were not enough, it is also possible to add ExpressionDebugger to debug within the mapping without losing efficiency, and solving one of the biggest disadvantages of using automatic mapping libraries.

For more information, check the abundant information on the project’s website https://github.com/MapsterMapper/Mapster, where you will also find all the code for the same.

Mapster is available to conveniently add to our project through a Nuget package, and is compatible with .Net Framework and .Net Standard.

In summary, one of the best libraries (if not the best) at the moment for mapping objects, allowing us to create cleaner and more maintainable solutions, without affecting the performance of the application.