How to copy value from class X to class Y with the same property name in c#?
- by Samnang
Suppose I have two classes:
public class Student
{
public int Id {get; set;}
public string Name {get; set;}
public IList<Course> Courses{ get; set;}
}
public class StudentDTO
{
public int Id {get; set;}
public string Name {get; set;}
public IList<CourseDTO> Courses{ get; set;}
}
I would like to copy value from Student class to StudentDTO class:
var student = new Student();
StudentDTO studentDTO = student;
How can I do that by reflection or other solution?