I have an object (A) with many properties. I make a new object B that extends the object A with some new properties.
Then I have an method AA that returns the instance of object A, but in my current method BB I use the new instance of object B.
Do I have any way to use the return of the method AA to assign in the object B?, How do I assign to B avoiding copy property by property?
class A
{
string a1 {get; set;}
// ...
string a50 {get; set;}
}
class B: A
{
string bState {get; set;}
string bMessage {get; set;}
}
class ObjAA
{
public static AA ReturnAA()
{
AA oAA = new AA();
//...
return oAA;
}
}
class ObjBB
{
public void UseBB()
{
BB oBB = new BB();
var aa = ObjAA.ReturnAA();
// How do I assign to B avoiding property by property?
}
}
thanks
Marc Gravell mentions one way, which is fine.
Another is to just have the method return an instance of
Bfor you. How? Use generics.Then: