I have a complex objectA of type MyObject. I would like to create multiple variations of this MyObject based on a specific objectA.
public class MyObject()
{
int myAttr1;
string myAttr2;
MyChildObject1 myChildObject1;
MyChildObject2 myChildObject2;
...
}
public List<MyObject> createVariations(MyObject myObject)
{
List<MyObject> myObjectList = new List<MyObject>();
MyObject myFirstVariation = myObject;
myFirstVariation.myAttr1 = myObject.myAttr1 + 5;
myObjectList.Add(myFirstVariation);
// TODO: Do different specific variations of the same source object!
...
return myObjectList;
}
I know that this won't work because I am just creating multiple references to myObject and I am changing its parameters, so there will be lots of references of the same object in the list.
How would I get a list of objects with different configurations. Do I really have to create a copy constructor for these objects? Thank you in advance.