I have got two user defined CLR objects which are identical and only differ in name, for example this code:
public class Person
{
public string Name { get; set; }
public string Address { get; set; }
public string LastName { get; set; }
public string ETC { get; set; }
}
public class PersonData
{
public string Name { get; set; }
public string Address { get; set; }
public string LastName { get; set; }
public string ETC { get; set; }
}
I know that this can be done by creating an object from either of these CLR's and than pass all properties one by one to it.
But is there another way? I got a few CLR's that are pretty big, 15+ properties.
[Edit] Some more context. The classes where already there. I generated a model from the database using EntityFramework
. The database has almost the exact same structure as the classes.
Also, it's a lot of code that was already there. These classes also inherit from several interfaces etc. Refactoring now is not an option, so i'm looking for an easy fix for now.
Assumming you don't want both classes to inherit from an interface you can try Automapper it's a library for automatically mapping similar classes.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments