Faisal.Map.Object 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Faisal.Map.Object --version 1.0.3
NuGet\Install-Package Faisal.Map.Object -Version 1.0.3
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="Faisal.Map.Object" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Faisal.Map.Object --version 1.0.3
#r "nuget: Faisal.Map.Object, 1.0.3"
#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 Faisal.Map.Object as a Cake Addin
#addin nuget:?package=Faisal.Map.Object&version=1.0.3

// Install Faisal.Map.Object as a Cake Tool
#tool nuget:?package=Faisal.Map.Object&version=1.0.3

How to use:

  1. For simple class Object: Students student = _dbContext.Students.Where(a=>a.ID == 1); StudentsViewModel records = student.MapProperties<Students>();

  2. For List class Object List<StudentsViewModel> studentsVM = new List<StudentsViewModel>(); List<Students> students = _dbContext.Students.ToList(); students.MapListProperties<Students, StudentsViewModel>(students);

Example scenario:

Let me start with one scenario. Just imagine we have an object which has lots of public properties and we need to use only some properties of it for the user profile method. For example, we have a class Teacher_Interview and another class named Teacher_College.

Public class Teacher_Interview { Public int UID {get; set;} Public string Name {get; set;} Public string Email {get; set;} Public string Subject {get; set;} }

Public class Teacher_College { Public int TID {get; set;} Public string Name {get; set;} Public string Email {get; set;} }

Here, we have written both the classes. As we can see, we have a Teacher_Interview class that contains its public properties. Now, we need to use the Teacher_college class object and want the same values from the Teacher_Interview class object. For example, we wrote Teacher_Interview object.

Teacher_Interview ti = new Teacher_Interview() { UID = 101 Name = “Faisal Pathan” Email = faisalmpathan@gmail.com Subject = “.NET” } Now, in a normal case, we copy/use the Teacher_Interview object value in Teacher_College like below.

Teacher_College tc = new Teacher_College() { TID = ti.UID, Name = ti.Name, Email = ti.Email } Just think about what happens if we have 40-50 or more than 50 properties. In this case, we have to write the same line 40 to 50 times which is definitely a time-consuming and boring thing. It is also possible to forget to assign some of the properties which will result in an error. So, what is the solution for that? We can use System.reflection namespace and classes. Here, I wrote a generic method, namely “MatchAndMap” which copies the same name properties from Teacher_Interview class object to the Teacher_College class object.

Var records = (Teacher_Interview_class_object).MapProperties<Teacher_College_class_object>();

Product Compatible and additional computed target framework versions.
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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
1.0.4 1,001 2/22/2019
1.0.3 859 2/22/2019
1.0.2 855 2/21/2019

Map List method is added.