YGMapper 2.1.0

dotnet add package YGMapper --version 2.1.0                
NuGet\Install-Package YGMapper -Version 2.1.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="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YGMapper --version 2.1.0                
#r "nuget: YGMapper, 2.1.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.
// Install YGMapper as a Cake Addin
#addin nuget:?package=YGMapper&version=2.1.0

// Install YGMapper as a Cake Tool
#tool nuget:?package=YGMapper&version=2.1.0                

YGMapper

A simple mapper that maps one DTO to another DTO where the DTO types may or may not be identical. It can map DataTable to List<T> as well. Will support .net 6 and up

Installation

Include this package in the project file

Usage

for mapping all matching fields:

MapObjects mo1 = new MapObjects();   
var result = mo1.Map<Entity2>(entity1);   

or for mapping with included fields only (this will only include "Name", "EmailAddress" fields):

MapObjects mo2 = new MapObjects(new string[] { "Name", "EmailAddress" }, null);   
var result2 = mo2.Map<Entity2>(entity1);  

or for mapping with excluded fields (this will exclude "EmailAddress" field):

MapObjects mo3 = new MapObjects(null, new string[] { "EmailAddress" });   
var result3 = mo3.Map<Entity2>(entity1);   

For mapping 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);  

For mapping DataTable:

MapObjects modb = new MapObjects();
List<ViolationEntity> violationEntities = modb.Map<ViolationEntity>(ds.Tables[0]);

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

Contributing

Any new ideas on how to enhance this class without adding much complexity, please adhere to SOLID principle

License

This project is licensed under the MIT License(LICENSE).

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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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 99 5/31/2024
2.0.0 106 5/15/2024
1.0.0 110 5/15/2024

Support .net 6 and above, added mapping from DataTable to List<T>