I want to use method ‘IComponentMemento.SaveState/RestoreState’, but I can’t get ‘IComponentMemento’ by ‘IoC.Get<IComponentMemento>()’ or ‘[ImportingConstructor]’.
IComponentMemento is not a service that can be imported from IoC.
Use IoC.Get<IUndoHelper>() or import to get the undo helper, which has method CreateComponentMemento
thanks, I can get the status now, but I think it not really works.
IComponentMemento componentMemento = IoC.Get<IUndoHelper>().CreateComponentMemento(); public void GetComponentStatus() { if (selectedComponent != null) { componentMemento.SaveState(selectedComponent); } } public void SetComponentStatus() { IoC.Get<IApplication>().World.DeleteComponent(selectedComponent); componentMemento.RestoreState(); }
When I code like that, it will create a new component which name is the same as the selected component and the world will exist two components with the same name.
However, when I delete the selected component, the new component can’t run.
the gif will show how it works.
Because IComponentMemento.RestoreState() will create a new component ,so I just can delete the selected component, which deletes the connection of the component. However, use python .saveState() can work…
Maybe .NET ISimcomponent api should add a method for saving state?