YGMapper 2.1.0
dotnet add package YGMapper --version 2.1.0
NuGet\Install-Package YGMapper -Version 2.1.0
<PackageReference Include="YGMapper" Version="2.1.0" />
paket add YGMapper --version 2.1.0
#r "nuget: YGMapper, 2.1.0"
// 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 | 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 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. |
-
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.
Support .net 6 and above, added mapping from DataTable to List<T>