Let’s say we have 2 classes:
public class A
{
public int P1 {set; get;}
public int P2 {set; get;}
}
public class B
{
public int P1 {set; get;}
public int P2 {set; get;}
public int P3 {set; get;}
public int P4 {set; get;}
}
May I convert it in some way to initialize the members of them which have the same name?
I mean if .NET has something to exclude operations like:
A.P1 = B.P1
A.P2 = B.P2
B.P1 = A.P1
B.P2 = A.P2
and ignore other members…
Is it possible to do?
You could extract the common properties to an interface.
Then you can do this:
EDIT:
Perhaps you could look into the https://github.com/AutoMapper/AutoMapper library