Mappy.dotNet 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mappy.dotNet --version 1.0.0
                    
NuGet\Install-Package Mappy.dotNet -Version 1.0.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="Mappy.dotNet" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mappy.dotNet" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Mappy.dotNet" />
                    
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 Mappy.dotNet --version 1.0.0
                    
#r "nuget: Mappy.dotNet, 1.0.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.
#addin nuget:?package=Mappy.dotNet&version=1.0.0
                    
Install Mappy.dotNet as a Cake Addin
#tool nuget:?package=Mappy.dotNet&version=1.0.0
                    
Install Mappy.dotNet as a Cake Tool

🍁Mappy - Object Mapping

Introduction

Mappy is a lightweight object mapping utility for C# applications. It allows you to easily map objects between models and DTOs, handle nested objects, and map collections. This utility supports both synchronous and asynchronous mapping operations, with options for custom transformations.


Features

  1. Simple Object Mapping: Map properties between objects with identical names and types.
  2. Nested Object Mapping: Automatically maps nested properties.
  3. Collection Mapping: Handles collections of objects and maps them to the destination collection type.
  4. Custom Mapping: Supports custom transformations using lambda expressions.
  5. Asynchronous Mapping: Enables async operations for custom transformations.
  6. Null Safety: Handles null values gracefully.
  7. Support mapping private properties.

Usage

1. Basic Mapping

var product = new Product
{
    Id = 1,
    Name = "Laptop",
    Price = 1200.50m,
    Category = new Category { Id = 10, Name = "Electronics" }
};

var productDto = product.Map<ProductDto>();
Console.WriteLine($"Product DTO: {productDto.Name}, {productDto.Category.Name}");

2. Custom Mapping

var product = new Product
{
    Id = 1,
    Name = "Laptop",
    Price = 1200.50m
};

var productDto = product.Map<ProductDto>(dto =>
{
    dto.Name = product.Name.ToUpper();
});

Console.WriteLine($"Custom Product DTO: {productDto.Name}");

3. Async Mapping

var product = new Product { Id = 1, Name = "Laptop", Price = 1200.50m };

var productDto = await product.MapAsync<ProductDto>(async dto =>
{
    dto.Name = await Task.FromResult(dto.Name.ToUpper());
});

Console.WriteLine($"Async Product DTO: {productDto.Name}");

4. Collection Mapping

var products = new List<Product>
{
    new Product { Id = 1, Name = "Laptop", Price = 1200.50m },
    new Product { Id = 2, Name = "Phone", Price = 800.00m }
};

var productDtos = products.MapCollection<ProductDto>();
productDtos.ForEach(dto => Console.WriteLine($"{dto.Id} - {dto.Name}"));

5. Mapping Nested Collections

var order = new Order
{
    Id = 100,
    CustomerName = "John Doe",
    Items = new List<OrderItem>
    {
        new OrderItem { ProductName = "Laptop", Quantity = 1 },
        new OrderItem { ProductName = "Mouse", Quantity = 2 }
    }
};

var orderDto = order.Map<OrderDto>();
Console.WriteLine($"Order DTO: {orderDto.CustomerName}");
orderDto.Items.ForEach(item => Console.WriteLine($"{item.ProductName} - {item.Quantity}"));

Notes

  1. Performance: This mapper is not optimized for very large datasets or scenarios with high-frequency mapping needs. Use with caution for such cases.
  2. Limitations:
    • Cannot handle circular references.

License

This project is open source and can be freely modified and distributed.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.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
2.1.0 109 4 months ago
2.0.1 98 5 months ago
1.0.0 97 5 months ago