Friday, February 1, 2019

Generic Extension Method to Map Objects From One Type to Another

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.



from DZone.com Feed http://bit.ly/2CVGM87

No comments:

Post a Comment