YGMapper 3.0.0
dotnet add package YGMapper --version 3.0.0
NuGet\Install-Package YGMapper -Version 3.0.0
<PackageReference Include="YGMapper" Version="3.0.0" />
<PackageVersion Include="YGMapper" Version="3.0.0" />
<PackageReference Include="YGMapper" />
paket add YGMapper --version 3.0.0
#r "nuget: YGMapper, 3.0.0"
#:package YGMapper@3.0.0
#addin nuget:?package=YGMapper&version=3.0.0
#tool nuget:?package=YGMapper&version=3.0.0
YGMapper
A simple object mapper for .NET that maps one DTO to another DTO where the types may or may not be identical.
Also supports mapping DataTable to List<T> and vice versa.
Supports .NET 8 and up.
Installation
Include this package in your project file:
xml <PackageReference Include="YGMapper" Version="3.0.0" />
Usage
Map all matching fields
MapObjects mo1 = new MapObjects();
var result = mo1.Map<Entity2>(entity1);
Map with included fields only
MapObjects mo2 = new MapObjects(new string[] { "Name", "EmailAddress" }, null);
var result2 = mo2.Map<Entity2>(entity1);
Map with excluded fields
MapObjects mo3 = new MapObjects(null, new string[] { "EmailAddress" });
var result3 = mo3.Map<Entity2>(entity1);
Mapping into an existing entity
Entity2 e2 = new Entity2()
{
Entity2Id = 1,
Name = "Butter",
EmailAddress = "butter@butter.com"
};
MapObjects mo6 = new MapObjects(null, new string[] { "Name", "EmailAddress", "Entity2Id" });
var result6 = mo6.Map<Entity2>(entity1, ref e2);
Mapping DataTable to List<T>
MapObjects modb = new MapObjects();
List<ViolationEntity> violationEntities = modb.Map<ViolationEntity>(ds.Tables[0]);
Mapping List<T> to DataTable
MapObjects mo0 = new MapObjects();
DataTable dt = mo0.ToDataTable<Entity3>(entity1.Projects);
Output
The Map<T>(object source) method returns:
Tuple<bool, string, T>
Item1 → Success flag
Item2 → Status / error message
Item3 → Mapped destination object
The overload Map<T>(object source, ref T destination) returns:
Tuple<bool, string>
Examples
Test project is provided in the solution to illustrate how to map a DTO, with included or excluded field names.
Output:
The output is Tuple<bool,string,T> , where Item1 represents whether or not the function has executed successfully, Item2 states the success or error message, and Item3 is the output DTO where the source object is mapped to.
Overload output is Tuple<bool,string>, where the destination object is passed as a ref object to Map function
Dependencies
none
Release Notes 3.0.0:
Breaking: Mapping correctness & safety overhaul
✅ Fixed nullable type mapping (int → int?, DateTime → DateTime?)
✅ Added safe type conversion during mapping
✅ Fixed include/exclude filter logic
✅ Prevented mapping into read-only properties
✅ Improved error diagnostics for mapping failures
✅ Normalized DataTable null handling
⚠️ This release includes behavioral changes to mapping logic and is a breaking change for consumers relying on previous implicit behavior.
If you rely on exact 2.x mapping semantics, stay on 2.3.x. v3.x prioritizes correctness, null safety, and explicit type conversion.
Contributing
This project was built with a mix of human experience and AI-assisted refactoring.
PRs and improvements are welcome.
License
This project is licensed under the MIT License(LICENSE).
| 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 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. |
-
net8.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.
Breaking: Fixed nullable/type conversion issues and improved mapping safety (see README for migration notes).