I have two class with nearly exactly same attributes, the only difference is
class B's property setter does some argument checking.
[Serializable]
class A
{
private string a;
public string AA
{
get { return a; }
set { a = value; }
}
}
[Serializable]
class B
{
private string a;
public string AA
{
get { return a; }
set
{
if (string.IsNullOrEmpty(value))
{
throw new ApplicationException();
}
a = value;
}
}
}
I want to do the following:
A a = new A();
a.AA = "123123";
B b = (B)a; -- Copy a's attribute values to b.
Please tell me how to implement a generic function to support copying
namesake fields from one class instance to another even when they belongs to
different class type.
Thanks.
zlf