GithubHelp home page GithubHelp logo

gerrey / mapster Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jbogard/mapster

0.0 0.0 0.0 1.23 MB

A fast, fun and stimulating object to object Mapper

License: MIT License

C# 95.63% PowerShell 4.31% Batchfile 0.07%

mapster's Introduction

Mapster Icon

Mapster - The Mapper of Your Domain

Writing mapping methods is a machine job. Do not waste your time, let Mapster do it.

NuGet

Get it

PM> Install-Package Mapster

Basic usage

Mapping to a new object

Mapster creates the destination object and maps values to it.

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

Mapping to an existing object

You create the object, Mapster maps to the object.

sourceObject.Adapt(destObject);

Queryable Extensions

Mapster also provides extensions to map queryables.

using (MyDbContext context = new MyDbContext())
{
    // Build a Select Expression from DTO
    var destinations = context.Sources.ProjectToType<Destination>().ToList();

    // Versus creating by hand:
    var destinations = context.Sources.Select(c => new Destination {
        Id = p.Id,
        Name = p.Name,
        Surname = p.Surname,
        ....
    })
    .ToList();
}

Generating models & mappers

No need to write your own DTO classes. Mapster provides Mapster.Tool to help you generating models. And if you would like to have explicit mapping, Mapster also generates mapper class for you.

[AdaptTo("[name]Dto"), GenerateMapper]
public class Student {
    ...
}

Then Mapster will generate:

public class StudentDto {
    ...
}
public static class StudentMapper {
    public static StudentDto AdaptToDto(this Student poco) { ... }
    public static StudentDto AdaptTo(this Student poco, StudentDto dto) { ... }
    public static Expression<Func<Student, StudentDto>> ProjectToDto => ...
}

What's new

Why Mapster?

Performance & Memory efficient

Mapster was designed to be efficient on both speed and memory. You could gain a 4x performance improvement whilst using only 1/3 of memory. And you could gain up to 12x faster performance with

Method Mean StdDev Error Gen 0 Gen 1 Gen 2 Allocated
'Mapster 6.0.0' 108.59 ms 1.198 ms 1.811 ms 31000.0000 - - 124.36 MB
'Mapster 6.0.0 (Roslyn)' 38.45 ms 0.494 ms 0.830 ms 31142.8571 - - 124.36 MB
'Mapster 6.0.0 (FEC)' 37.03 ms 0.281 ms 0.472 ms 29642.8571 - - 118.26 MB
'Mapster 6.0.0 (Codegen)' 34.16 ms 0.209 ms 0.316 ms 31133.3333 - - 124.36 MB
'ExpressMapper 1.9.1' 205.78 ms 5.357 ms 8.098 ms 59000.0000 - - 236.51 MB
'AutoMapper 10.0.0' 420.97 ms 23.266 ms 35.174 ms 87000.0000 - - 350.95 MB

Step into debugging

Step-into debugging lets you debug your mapping and inspect values just like your code. image

Code Generation

Code generation allows you to

  • Validate mapping at compile time
  • Getting raw performance
  • Seeing your mapping code & debugging
  • Finding usage of your models' properties

There are currently two tools which you can choose based on your preferences.

Change logs

https://github.com/MapsterMapper/Mapster/releases

Usages

Acknowledgements

JetBrains kindly provides Mapster with a free open-source licence for their Resharper and Rider.

  • Resharper makes Visual Studio a much better IDE
  • Rider is fast & powerful cross platform .NET IDE

image

mapster's People

Contributors

chaowlert avatar eswann avatar satano avatar sergergood avatar napalu avatar hpcsc avatar eric-swann-q2 avatar burgyn avatar cmann-andagon avatar sven-n avatar miou-gh avatar dotnetchris avatar bryant1410 avatar klesouza avatar wk-j avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.