Mappy.dotNet
1.0.0
There is a newer version of this package available.
See the version list below for details.
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" />
<PackageReference Include="Mappy.dotNet" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Mappy.dotNet&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
🍁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
- Simple Object Mapping: Map properties between objects with identical names and types.
- Nested Object Mapping: Automatically maps nested properties.
- Collection Mapping: Handles collections of objects and maps them to the destination collection type.
- Custom Mapping: Supports custom transformations using lambda expressions.
- Asynchronous Mapping: Enables async operations for custom transformations.
- Null Safety: Handles null values gracefully.
- 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
- Performance: This mapper is not optimized for very large datasets or scenarios with high-frequency mapping needs. Use with caution for such cases.
- Limitations:
- Cannot handle circular references.
License
This project is open source and can be freely modified and distributed.
Product | Versions 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.