المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Is there any technique available for copying one object of class A to another object of class B ?



C# Programming
08-06-2010, 08:52 AM
Hi,
I am wondering, is there any technique available to copy an object to another object when the objects are of different class but the signature of these classes are same (100% identical) ? For example, if I have

class A
{
public string Name;
public string EmailAddress;
}
and

class B
{
public string Name;
public string EmailAddress;
}
Now, in my code, I have a::A, b::B.

I want to copy all property values from b to a, but I have to do it manually by iterating all properties of b to a one by one like this.

a.Name = b.Name;
a.EmailAddress = b.EmailAddress;
I wish if there were any techniq to automate this task!! I know about Copy/Cloning techniques where the objects are from same class. But as you see my objects are from different class. If my class were so simply like this, I would not have worried, but my class A and B has around 50 properties which is hard to maintain. So, I would appreciate any idea.

Regards.