Files
MappersBenchmarks/MappersBenchmarks/MapperlyMapper.cs
T
Thom Lamb 63bc9f1fd5 feat: Introduce object mapper benchmarking project
This project provides a comparative analysis of popular .NET object-to-object
mapping libraries, including AutoMapper, TinyMapper, Mapster, and Mapperly,
against a hand-written and a generated manual mapper.

It uses BenchmarkDotNet to measure performance and memory allocation when
mapping a complex Spotify album DTO structure.
2026-06-23 10:26:13 -05:00

138 lines
3.6 KiB
C#

using MappersBenchmarks.Models;
using Riok.Mapperly.Abstractions;
namespace MappersBenchmarks
{
[Mapper]
public partial class MapperlyMapper
{
public partial SpotifyAlbum Map(SpotifyAlbumDto spotifyAlbumDto);
//public partial SpotifyAlbum Map(SpotifyAlbumDto spotifyAlbum)
//{
// var newItem = new SpotifyAlbum()
// {
// AlbumType = spotifyAlbum.AlbumType,
// TotalTracks = spotifyAlbum.TotalTracks,
// AvailableMarkets = spotifyAlbum.AvailableMarkets,
// ExternalUrls = Map(spotifyAlbum.ExternalUrls),
// Href = spotifyAlbum.Href,
// Id = spotifyAlbum.Id,
// //Images = Map(spotifyAlbum.Images),
// Name = spotifyAlbum.Name,
// ReleaseDate = spotifyAlbum.ReleaseDate,
// ReleaseDatePrecision = spotifyAlbum.ReleaseDatePrecision,
// Restrictions = Map(spotifyAlbum.Restrictions),
// Type = spotifyAlbum.Type,
// Uri = spotifyAlbum.Uri,
// //Copyrights = Map(spotifyAlbum.Copyrights),
// //ExternalIds = Map(spotifyAlbum.ExternalIds),
// //Genres = Map(spotifyAlbum.Genres),
// Label = spotifyAlbum.Label,
// Popularity = spotifyAlbum.Popularity,
// //Artists = Map(spotifyAlbum.Artists),
// //Tracks = Map(spotifyAlbum.Tracks),
// };
// return newItem;
//}
/*
private partial List<string> Map(IList<string> source)
{
var destination = new List<string>();
if (source == null) return null;
foreach (var item in source)
{
destination.Add(item);
}
return destination;
}
private partial string[] Map(IList<string> source)
{
var destination = new List<string>();
if (source == null) return null;
foreach (var item in source)
{
destination.Add(item);
}
return destination.ToArray();
}
private partial Image Map(ImageDto item)
{
if (item == null) return null;
var newItem = new Image()
{
Url = item.Url,
Height = item.Height,
Width = item.Width,
};
return newItem;
}
private partial ExternalUrl Map(ExternalUrlDto item)
{
if (item == null) return default;
var newItem = new ExternalUrl()
{
Spotify = item.Spotify,
};
return newItem;
}
private partial Restriction Map(RestrictionDto item)
{
if (item == null) return null;
var newItem = new Restriction()
{
Reason = item.Reason,
};
return newItem;
}
private partial ExternalId Map(ExternalIdDto item)
{
if (item == null) return null;
var newItem = new ExternalId()
{
Isrc = item.Isrc,
Ean = item.Ean,
Upc = item.Upc,
};
return newItem;
}
private partial List<string> Map(IEnumerable<string> source)
{
var destination = new List<string>();
if (source == null) return null;
foreach (var item in source)
{
destination.Add(item);
}
return destination;
}
*/
}
}