Dango 0.2.0

dotnet add package Dango --version 0.2.0
                    
NuGet\Install-Package Dango -Version 0.2.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="Dango" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dango" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Dango" />
                    
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 Dango --version 0.2.0
                    
#r "nuget: Dango, 0.2.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 Dango@0.2.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=Dango&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Dango&version=0.2.0
                    
Install as a Cake Tool

Dango - Compile-Time Safe Enum Mapping for C#

Why?

Currently the most used C# mapping library is AutoMapper, which I am not a big fan of, because it shifts potential errors to runtime instead of compile time. This can be a problem, especially in large projects, where a simple refactoring change can break the mapping without the developer noticing it until runtime.

The problem becomes even more apparent when it comes to mapping enums. If a new value is added to the source enum, there is no compile-time check to ensure that the corresponding value is added to the destination enum as well, leading to potential runtime mapping errors.

You can solve this problem for everything except enums by simply not using AutoMapper and writing the mapping code manually, but that doesn't work for enums as using a switch statement doesn't solve the problem—there is no compile-time check to ensure that all enum values are handled and no values are missing from the destination enum.

What?

Dango is a source generator that generates mapping code for enums at compile time, ensuring that all enum values are handled and mapped correctly. If a new value is added to the source enum, the developer will get a compile-time error if the corresponding value is not added to the destination enum as well.

Dango is designed to be simple and easy to use, with minimal configuration required and allows several options to customize the mapping behavior.

Features

  • Compile-Time Safety: Get errors at compile time, not runtime
  • Multiple Mapping Strategies: Map by name or by value
  • Default Values: Specify a default destination value for unmapped source values
  • Custom Overrides: Override specific mappings when needed
  • Multiple Destinations: Map a single source enum to multiple destination enums
  • Nullable Support: Automatic generation of nullable variants for all mappings
  • Clean Generated Code: Extension methods with switch expressions for optimal performance

Installation

dotnet add package Dango

Usage

Basic Setup

Create a registrar class implementing IDangoMapperRegistrar:

using Dango.Abstractions;

public class MyRegistrar : IDangoMapperRegistrar
{
    public void Register(IDangoMapperRegistry registry)
    {
        // Basic mapping (by name)
        registry.Enum<SourceStatus, DestinationStatus>();
        
        // Map by value instead of name
        registry.Enum<SourcePriority, DestinationPriority>().MapByValue();
        
        // Provide default for unmapped values
        registry.Enum<SourceState, DestinationState>()
            .WithDefault(DestinationState.Unknown);
        
        // Override specific mappings
        registry.Enum<SourceRole, DestinationRole>()
            .WithOverrides(new Dictionary<SourceRole, DestinationRole>
            {
                { SourceRole.Admin, DestinationRole.Administrator }
            });
        
        // Combine options
        registry.Enum<SourceType, DestinationType>()
            .MapByValue()
            .WithDefault(DestinationType.Other)
            .WithOverrides(new Dictionary<SourceType, DestinationType>
            {
                { SourceType.Special, DestinationType.Custom }
            });
        
        // Map to multiple destinations
        registry.Enum<ApiStatus, DatabaseStatus>();
        registry.Enum<ApiStatus, DisplayStatus>();
    }
}

Generated Code

Dango generates extension methods for each source enum:

// Non-nullable extension
DestinationStatus status = sourceStatus.ToDestinationStatus();

// Nullable extension (generated automatically)
DestinationStatus? nullableStatus = nullableSource.ToDestinationStatus();

Handling Same Enum Names

When enums have the same name in different namespaces, Dango adds namespace prefixes:

// Api.Status -> Database.Status generates:
var dbStatus = apiStatus.ToDatabaseStatus();

Error Handling

Dango provides compile-time diagnostics for:

  • Invalid enum types
  • Duplicate mappings
  • Unmapped source values without defaults

Generated Code Location

All generated code is placed in {AssemblyName}.Generated.Dango.Mappings namespace.

There are no supported framework assets in this 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
0.2.0 134 10/23/2025