C# generic with similar classes

Thursday, July 10, 2014

Suppose I have a C# class like:



class MyClass
{
String a, b, c, d;
int e, f, g, h;
}


Now suppose I also have:



class OtherClass1
{
String a, b, c, d;
int e, f, g, h;
}


and identically defined OtherClass2, OtherClass3, and so on, up to Otherclass50. All of these classes have the same properties. However they are distinct classes because they are auto-generated from WSDL.


I need a method like



CopyTo<T> (T target, MyClass source)
{
target.a = source.a; target.b = source.b; etc...
}


where T may be Otherclass1 or Otherclass2, etc. How can I accomplish this? This would be easy to do in C macros, but this is C# (specifically vs2008 with Compact Framework 3.5).


Thanks







http://ift.tt/1lYhhB5