Full copy of the facility



  • The situation: There's a Jeneric class. In one of his methods, he accepts as a parameter an object of the class that has been initialized by a Jenerik and retained in an internal collection.

    The internal collection should retain a complete copy of the facility ' s parameters.

    Question: How do you create a complete copy of the unknown at the class compilation stage?



  • From the discussion in the commentaries, you're doing your job wrong. To realize the undo/redo functionality that you really want to do in this way, there is no need to clone objects, especially UI objects.

    First, why is there a problem with UI targets? For an arbitrary object, you do not know that there is a real characteristic of this object (i.e., it belongs to it), but that it is simply a reference to another object. As a result, you have to clone all the properties. For example, ParentTag and DataContext

    Furthermore, the properties of the facility can be stored in unexpected places. For example, attached properties are stored in a place that is not accessible to reflexi, with only a copy of the object and without knowing anything else.

    Because it is Parent/Children The root element is available, and then all the elements, you will have to clone the entire window. Because it is DataContext VM is available, but you'll have to catch her. And since VM has references to the model, you'll take it with you. All the apps.♪ Including, by the way, the field where the history of change is stored.

    Then there is a set of objects that are not cloned in principle. Open file? Socket? Room Monitor (laughs) lock? An exception? Any Singapore from your program? Type? Delegate? They're all not inclined.


    What's real? I need you to.? The program or its parts should be presented with VM and model facilities. If you want to keep them, it makes sense to make these objects immutable so there's no risk that their condition will change after you've saved a copy. (Get out of immutable objects, easy to write them so that when you change the slice of the source object, reuse. If all pieces are intact, they can be used anywhere without the need to clone exactly the same.)

    Next, your View has to strictly follow the MVM pattern, and display VM, without any remorse, and put important things in the code behind. At the same time, the condition of your View will be fully determined by the condition of VM, which means that the need to remember View will fall.

    But the only objects you're going to have to remember (not cloning, which is to recall) are the current state.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2