In this article, we will talk about my first NuGet which map objects and their properties from one type to another.
To save you some time and complexity, take a look at this tool to map objects from one type to another.
I uploaded my first Mapper NuGet to Nuget’s website; you can find it here. It’s designed to help developers map object properties from one type to another without adding complex lines of code.
For example, if we have one entity table which has 25 properties or more, and we want to use ViewModel with all these properties, we have to write the same line of code 25 times.
viewModel.Col1 =entityObj.Col1; viewModel.Col2 =entityObj.Col2; viewModel.Col3 =entityObj.Col3; …
This is definitely time-consuming, monotonous, and makes our code unnecessary verbose. It is also possible to mismatch the properties, which will result in an error. So, to overcome this kind of thing, I uploaded the NuGet package which you can install using the below methods.
Using Package Manager
Install-Package Faisal.Map.Object -Version 1.0.4
Using .NET CLI
dotnet add package Faisal.Map.Object --version 1.0.4
Using Paket CLI
paket add Faisal.Map.Object --version 1.0.4
Using NuGet – Solution
I also published an article about a Generic Extension method which you can read here. This article explains only mapping for the single class/object. In NuGet, I added to map
Listclass , too.
To use the project, issue the appropriate commands.
To Map Single Object.
Students student = _dbContext.Students.Where(a=>a.ID == 1); StudentsViewModel records = student.MapProperties<Students>();
To Map List of Objects
List<StudentsViewModel> studentsVM = new List<StudentsViewModel>(); List<Students> students = _dbContext.Students.ToList(); students.MapListProperties<Students, StudentsViewModel>(studentsVM);
I hope this NuGet will be helpful and useful in your project. Please install it and give your valuable feedback and comments. Let me know how you like it and understand this blog and how I could improve it.