YGMapper 3.0.0

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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
3.0.0 216 2/11/2026
2.3.0 470 1/2/2025
2.2.0 442 1/2/2025
2.1.0 454 5/31/2024
2.0.0 460 5/15/2024
1.0.0 468 5/15/2024

Breaking: Fixed nullable/type conversion issues and improved mapping safety (see README for migration notes).