N-Level Undo

N-Level Undo

Old forum URL: forums.lhotka.net/forums/t/11551.aspx

AntonyM posted on Friday, August 24, 2012

Hi Everyone,

This is my first post so please bare with me.

I have  an object "Transport" which inherits from BusinessBase, this object has several properties one of which named "TransportType" which is of type ITransportType. I have 3 further objects that also inherit from BusinessBase and implement interface ITransportType these are name "Vehicle", "Motorbike", "Bicycle"

When a user edits these details through the front end they have a list of TransportTypes in a drop down and on selection I set the Transport.TransportType to a new object of the type they selected, so if they select Bicycle I create a new Bicycle object and set Transport.TransportType = Bicycle.

Everything works fine except the Undo, when the ui dialog opens I get the Transport object and call BeginEdit() the user then changes the TransportType property and clicks Cancel, I then call CancelEdit().

The CancelEdit() restores all the properties in the Transport object to their original values except the TransportType, I can only assume that this is because the property is storing an interface.I have tried to add


IEditableBusinessObject to the list of implemented interfaces on the ITransportType interface but still no joy.

Please could someone advise how I can get the Undo to support this scenario.

I am currently using version 3.6.2

Many thanks#



JonnyBee replied on Friday, August 24, 2012

You should not declare a property of the Interface type.

This is because an Interface is not serializable/deserializable. You need a concrete type to make the property serializable.

AntonyM replied on Tuesday, August 28, 2012

Hi JonnyBee,

I thought this may be the case, after reading your post I created a Abstract base class for TransportType which inherits from BusinessBase. I then changed "Vehicle, Motorbike, Bicycle" objects to inherit from the new TransportType abstract base class.

Unfortunately this doesn't work either, same result.



RockfordLhotka replied on Tuesday, August 28, 2012

You made your base class generic right? That should work fine, as it is a supported scenario.

The real answer though, is to use your interface scheme, along with concrete implementation classes (because CSLA, data binding, ORMs, and other tools generally ignore interfaces). Just make sure your interface derives from IEditableObject so it meets the requirement for the type C in BusinessListBase<T, C>.

Copyright (c) Marimer LLC