BonyadCode.Mapper.AspNetCore
1.0.1
dotnet add package BonyadCode.Mapper.AspNetCore --version 1.0.1
NuGet\Install-Package BonyadCode.Mapper.AspNetCore -Version 1.0.1
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="BonyadCode.Mapper.AspNetCore" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BonyadCode.Mapper.AspNetCore" Version="1.0.1" />
<PackageReference Include="BonyadCode.Mapper.AspNetCore" />
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 BonyadCode.Mapper.AspNetCore --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BonyadCode.Mapper.AspNetCore, 1.0.1"
#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 BonyadCode.Mapper.AspNetCore@1.0.1
#: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=BonyadCode.Mapper.AspNetCore&version=1.0.1
#tool nuget:?package=BonyadCode.Mapper.AspNetCore&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
In the name of God
BonyadCode.Mapper.AspNetCore
A lightweight and flexible object-to-object mapping utility for .NET. Supports automatic property mapping between classes, structs, and records using reflection. Ideal for DTO transformations, data shaping, and lightweight model copying.
โจ Features
- Universal Mapping: Works with classes, structs, and records.
- Zero Configuration: Automatically maps matching property names.
- Safe Type Conversion: Converts between compatible property types (e.g.,
int
todouble
). - Minimal Footprint: One simple method, no dependencies or profiles.
- Extension-Based: Clean syntax via
source.MapTo<T>()
.
๐ฆ Installation
dotnet add package BonyadCode.Mapper.AspNetCore
๐ Quick Examples
โ Map Between Records
var source = new PersonDto { Name = "Ali", Age = 30 };
var result = source.MapTo<PersonEntity>();
โ Map Between Structs
var pointDto = new PointDto { X = 5, Y = 10 };
var result = pointDto.MapTo<Point>();
โ Map Between Anonymous and Concrete Types
var anon = new { Username = "user123", Email = "user@example.com" };
var userDto = anon.MapTo<UserDto>();
๐ How It Works
- Maps properties by name match (case-sensitive).
- Supports type conversion via
Convert.ChangeType
for assignable values. - Ignores unreadable or unwritable properties.
- Throws meaningful errors if instantiation or mapping fails.
๐งช Sample Models
record PersonDto(string Name, int Age);
record PersonEntity { public string Name { get; set; } public int Age { get; set; } }
struct PointDto { public int X { get; set; } public int Y { get; set; } }
struct Point { public int X { get; set; } public int Y { get; set; } }
class UserDto { public string Username { get; set; } public string Email { get; set; } }
โ๏ธ Notes & Limitations
- Source and target properties must have the same name.
- Properties must be public instance properties.
- No nested object or collection support (yet).
- All target types must have a public parameterless constructor or be value types.
๐ง Internals
- Uses
Activator.CreateInstance<T>()
to support both value types and reference types. - Uses cached reflection lookups for performance in future versions (planned).
- Throws descriptive exceptions when instantiation or mapping fails.
๐ค Contributing
Contributions, ideas, and pull requests are welcome! GitHub โ
๐ License
Apache 2.0 โ see the LICENSE file.
๐ฆ Links
Usage Conditions:
- This program must not be used for any military or governmental purposes without the owner's consent.
- This program must not be used for any inhumane purposes.
- This program must not be used for any illegal or haram activities.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
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.