MapShark 1.0.3

dotnet add package MapShark --version 1.0.3
                    
NuGet\Install-Package MapShark -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MapShark" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MapShark" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MapShark" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MapShark --version 1.0.3
                    
#r "nuget: MapShark, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MapShark&version=1.0.3
                    
Install MapShark as a Cake Addin
#tool nuget:?package=MapShark&version=1.0.3
                    
Install MapShark as a Cake Tool

NuGet

What is MapShark?

MapShark is a mapping library that maps one object to another object simply and quickly.

How do I get started?

Using MapShark is quite simple.

To start using MapShark, simply add the following code to your project's Program.cs file (for Dependency Injection).

using MapShark.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMapShark();

You can then use it as follows:

using MapShark.Abstractions;

[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
    private readonly IMapper _mapper;
    public ExampleController(IMapper mapper)
    {
        _mapper = mapper;
    }

    [HttpGet]
    public ActionResult Map()
    {
        Source source = new Source
        {
            Id = 1,
            Name = "Name",
        };

        return Ok(_mapper.Map<Source, Destination>(source));
    }
}

Collection Mapping

MapShark allows mapping of IEnumerable based objects.

using MapShark.Abstractions;

[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
    private readonly IMapper _mapper;
    public ExampleController(IMapper mapper)
    {
        _mapper = mapper;
    }

    [HttpGet]
    public ActionResult Map()
    {
        List<Source> sources = new()
        {
            new Source()
            {
                Id = 1,
                Name = "Name",
            }
        };
        return Ok(_mapper.Map<Source, Destination>(sources));
    }
}

Flex Mapping

MapShark offers a flexible mapping structure for data transformations. Thanks to this structure:

  • Properties with Different Names: If there is a property like “FirstName” in the source object, you can map it to a different name like “Name” in the target object.

  • Custom Mappings: Even if the property names are not the same, you can define specific transformations or mappings to achieve the desired data transfer.

This makes it easier to transfer and transform data between objects with different naming conventions.

Using Flex Mapping

In order to use Flex Mapping, we need a class created from the IMappingProfile interface. After creating this class as below and adding the ConfigureMapping method to it, the first thing we need to do is to specify which mapping operation will be used in it, we do this with the For method. Then you can specify which source property to assign to which target with the Map method. The Map function can be used in a chained way.

using MapShark.Abstractions;
using MapShark.Configuration;

namespace Example
{
    public class MappingProfile : IMappingProfile
    {
        public void ConfigureMapping()
        {
            MapperConfigurationRegistry.For<Models.Class.Source, Models.Class.Destination>()
                    .Map(src => src.FirstName, dest => dest.Name)
                    .Map(src => src.Descr, dest => dest.Description);
        }
    }
}

Then just use the mapping for your related objects.

If you don't want to create a profiler in this way, you can use this construct instead, which will be executed just before the mapping.

using MapShark.Abstractions;

[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
    private readonly IMapper _mapper;
    public ExampleController(IMapper mapper)
    {
        _mapper = mapper;
    }

    [HttpGet]
    public ActionResult Map()
    {
        Source source = new Source
        {
            Id = 1,
            Name = "Name",
        };
        MapperConfigurationRegistry.For<Models.Class.Source, Models.Class.Destination>()
                                        .Map(src => src.Name, dest => dest.Firstname)
                                        .Map(src => src.Id, dest => dest.IdentityNumber);
        return Ok(_mapper.Map<Source, Destination>(source));
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 66 5/3/2025
1.0.2 63 5/3/2025
1.0.1 60 5/3/2025
1.0.0 64 5/3/2025