Add samples
Provide some complete mapper samples. Samples are a great way to get started for newer users or to check how specific features can be used.
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.
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.
Damn, you just gave me a reality check :| I'm one of those devs that maps objects like the example in ManyallyMapper.cs.
:tada: This issue has been resolved in version 2.6.0 :tada:
The release is available on:
- GitHub release
v2.6.0
Your semantic-release bot :package::rocket: