Coder Social home page Coder Social logo

Add samples about mapperly HOT 4 CLOSED

riok avatar riok commented on May 25, 2024 3
Add samples

from mapperly.

Comments (4)

CommonGuy avatar CommonGuy commented on May 25, 2024 4

An example snippet of generated code:

public partial ObjectsMapperBenchmark.SpotifyAlbum? Map(ObjectsMapperBenchmark.SpotifyAlbumDto? spotifyAlbumDto)
{
    if (spotifyAlbumDto == null)
        return default;
    var target = new ObjectsMapperBenchmark.SpotifyAlbum();
    target.AlbumType = spotifyAlbumDto.AlbumType;
    if (spotifyAlbumDto.Artists != null)
    {
        target.Artists = MapToArtistArray(spotifyAlbumDto.Artists);
    }

    // ...
    
    return target;
}

private ObjectsMapperBenchmark.Artist? MapToArtist(ObjectsMapperBenchmark.ArtistDto? source)
{
    if (source == null)
        return default;
    var target = new ObjectsMapperBenchmark.Artist();
    if (source.ExternalUrls != null)
    {
        target.ExternalUrls = MapToExternalUrls(source.ExternalUrls);
    }

    target.Href = source.Href;
    target.Id = source.Id;
    target.Name = source.Name;
    target.Type = source.Type;
    target.Uri = source.Uri;
    return target;
}

private ObjectsMapperBenchmark.Artist[] MapToArtistArray(ObjectsMapperBenchmark.ArtistDto[] source)
{
    var target = new ObjectsMapperBenchmark.Artist[source.Length];
    for (var i = 0; i < source.Length; i++)
    {
        target[i] = MapToArtist(source[i]);
    }

    return target;
}

Mapperly is only faster than naive manual mapping approaches (eg. https://github.com/mjebrahimi/Benchmark.netCoreMappers/blob/master/ObjectsMapperBenchmark/ManuallyMapper.cs). The main performance factor is the LINQ usage.

Mapperly cannot beat an optimized, manually written mapping method, but developers are often lazy and write sub-optimal code. We'll add samples (both of the usage and the generated code) to our documentation.

from mapperly.

samusaran avatar samusaran commented on May 25, 2024

Also, it would be nice to see some source code you generate, since one of the claims is that Mapperly is even faster than the naive manual mapping.

from mapperly.

samusaran avatar samusaran commented on May 25, 2024

Damn, you just gave me a reality check :| I'm one of those devs that maps objects like the example in ManyallyMapper.cs.

from mapperly.

github-actions avatar github-actions commented on May 25, 2024

🎉 This issue has been resolved in version 2.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from mapperly.

Related Issues (20)

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.