IEditableObject implementation

Aug 20, 2013 at 11:41 PM
Hi Tony -

Thanks for the great framework! Been using it on a new project and just ran into an issue that I was hoping you could shed some light on...

I am using using a custom model object that implements DataContract serialization - in some cases public properties intentionally do not carry the DataMember attribute and in others cases fields (and internal fields) are flagged for serialization. So the custom model objects clone/serialize/deserialize fine and as intended.

However, there seems to be a bit of a disconnect between the DataContract serialization and the manner in which the cloned Copy's values are copied back to the Original model in the EndEdit method as only public instance properties are copied back. So I have a situation in which the original model is now different from the edited model after the EndEdit call.

It would be nice if there was a way to handle this without rewriting the whole IEditableObject enchilada. Perhaps a mechanism to effectively override just the CopyValuesTo static extension - maybe a method like protected virtual CopyModelValues(TModel Original, TModel Copy) that just calls the Copy.CopyValuesTo(Original) by default.

Might be even nicer if the IEditableObject implementation could return the original model (after EndEdit) to a state that is exactly the same as if the copy model were cloned (as I'm assuming it would be dangerous to set the Model to a cloned version after EndEdit). Not sure how common this DataContract serialization logic disconnect scenario actually is though.