Morphant 0.4.0

dotnet add package Morphant --version 0.4.0
                    
NuGet\Install-Package Morphant -Version 0.4.0
                    
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="Morphant" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Morphant" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Morphant" />
                    
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 Morphant --version 0.4.0
                    
#r "nuget: Morphant, 0.4.0"
                    
#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.
#:package Morphant@0.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Morphant&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Morphant&version=0.4.0
                    
Install as a Cake Tool

<img src="logo.png" alt="Morphant logo" width="128" height="128">

Morphant

CI Line coverage NuGet NuGet downloads

Morphant is a compile-time object mapper for C#. It turns explicit configuration into strongly typed mapping code without runtime reflection. IMapper is the main application entry point.

If Morphant saves you time, you can support its development on Boosty.

Morphant is currently in the 0.x series. It focuses on core object mapping; automatic collection mapping, projection and several other general-purpose mapper features are not included yet. See Current limitations.

Install

The runtime package includes the source generator:

dotnet add package Morphant

The DI examples use Microsoft.Extensions.DependencyInjection, which is included in ASP.NET Core shared frameworks or available as a separate package.

Define a mapper

using Morphant;

public sealed class Customer
{
    public string Name { get; set; } = string.Empty;
}

public sealed class CustomerDto
{
    public string Name { get; set; } = string.Empty;
}

[MorphantMapper]
public sealed partial class ApplicationMapper : TypeMapper
{
    protected override void Configure(MapperBuilder builder) =>
        builder.Map<Customer, CustomerDto>();
}

Register with DI

Register the generated mapper and each source/destination mapping it implements:

using Microsoft.Extensions.DependencyInjection;

services.AddScoped<ApplicationMapper>();
services.AddScoped<ITypeMapper<Customer, CustomerDto>>(
    provider => provider.GetRequiredService<ApplicationMapper>());
services.AddScoped<IMapper, Mapper>();

Map objects

var created = mapper.Map<Customer, CustomerDto>(customer);

var existing = new CustomerDto();
existing = mapper.Map(customer, existing);

Always use the value returned by Update: a mapping may reuse the supplied destination or replace it.

Mappings can rely on conventions, flatten nested source member names, include selected nested source members, configure construction and members explicitly, call other registered mappings, explicitly route derived runtime source types, or use Convert for an ordinary synchronous C# algorithm.

Continue with the Quick start, choose a configuration method, or browse the documentation.

Requirements

  • C# 9 or newer;
  • a compiler host compatible with Roslyn 4.4.0 or newer;
  • a runtime compatible with netstandard2.0.

Roslyn 4.4.0 is the minimum host baseline, not a language-version cap. Consumer code can use newer C# features when its compiler and target types support them.

Versioning

Morphant follows Semantic Versioning. Patch releases within a 0.x minor line preserve compatibility. Until 1.0, minor releases may contain documented breaking changes. See the changelog.

License

Morphant is licensed under the MIT License.

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.
  • .NETStandard 2.0

    • No dependencies.

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
0.4.0 375 8/24/2026
0.3.0 110 8/20/2026
0.2.0 107 8/18/2026
0.1.0 408 8/16/2026

Adds explicit pair-local runtime polymorphism with ForDerived, most-specific class/interface dispatch, strict Update destination checks, value-type support, configurable unknown-derived handling, and dedicated diagnostics and runtime exceptions. Release notes: https://github.com/strangeman375/Morphant/blob/v0.4.0/CHANGELOG.md#040. Current limitations: https://github.com/strangeman375/Morphant/blob/v0.4.0/docs/limitations.md