I wrote a method:
class CopyableFloatCommand : FloatCommand
{
public CopyableFloatCommand DeepCopy(LocationHeaderDTO locHeader, string commandId,
List<FloatProductDetailsDTO> recountProuducts)
{
var newCommand = (CopyableFloatCommand)MemberwiseClone();
newCommand.Location = locHeader ?? newCommand.Location;
newCommand.CommandId = commandId ?? newCommand.CommandId;
newCommand.RecountProducts = recountProuducts ?? newCommand.RecountProducts;
return newCommand;
}
}
And then I call it through:
_tCheckinCommand = _pTCommand.DeepCopy(stagingLocHeadDto, SCICommand,
new List<FloatProductDetailsDTO>(_pTCommand.MoveProducts));
To deep copy an object of type FloatCommand.
Since the MemberwiseClone () method is protected, it must be called as you see above - you cannot use parsing of the FloatCommand type in the method parameter and call it through fc.MemberwiseClone (), for example. Since my method should work on the FloatCommand type, I created a new nested CopyableFloatCommand class that inherits from FloatCommand. The DeepCopy method then shallowly clones the FloatCommand, discards the child type, and changes some properties as necessary.
, . , , ? , UserCommand User? UserComand FloatCommand, Command. , ( , ), .
DeepCopy, , , ?
!