IEditableObject 和 IRevertibleChangeTracking 之间有什么区别?
IEditableObject 和 IRevertibleChangeTracking(均来自 System.ComponentModel 命名空间)?看起来第一个支持显式事务,而第二个则更加隐式 - 但最终结果是相同的。我应该如何在代码中实现这个?目前我在 BeginEdit 中什么也不做并调用 RejectChanges 和 AcceptChanges< /a> 在 EndEdit 和 取消编辑 分别。我的问题是,这也将接受在 BeginEdit 之前所做的更改。
这真的是微软想要的还是我试图实现两个互斥的接口?
What is the difference between IEditableObject and IRevertibleChangeTracking (both from the System.ComponentModel namespace)? It looks as if the first supports explicit transaction whilst the second is more implicit - but the net result is the same. How should I go about implementing this in code? At the moment I do nothing in BeginEdit and call RejectChanges and AcceptChanges in EndEdit and CancelEdit respectively. My problem is that this will also accept the changes made prior to the BeginEdit.
Is that really what Microsoft wanted or am I trying to implement two mutually exclusive interfaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这两个接口并不相互排斥。它们只是为了支持不同但有些相关的场景,这些场景也可以由同一个给定的类来实现。下面是一个快速说明:
IEditableObject 接口
IEditableObject 接口旨在支持对象在编辑时需要以某种特定方式管理其内部状态的场景。
因此,该接口包含显式标记编辑阶段何时开始、完成或中止的方法,以便可以在这些阶段采取适当的操作来修改对象的状态。
IRevertibleChangeTracking 接口
IRevertibleChangeTracking 接口旨在支持对象需要能够回滚到其先前状态的场景。
该接口具有标记何时应将对象的当前状态设为永久状态或应将其恢复到最后一个已知永久状态的方法。
The two interfaces are not mutually exclusive. They are simply intended to support different yet somewhat related scenarios, which might as well be implemented by the same given class. Here's a quick explanation:
IEditableObject Interface
The IEditableObject interface is designed to support the scenario where an object needs to manage its internal state in some particular way while it is being edited.
For that reason the interface includes methods that explicitly mark when the editing phase is started, completed or aborted, so that the appropriate actions can be taken to modify the object's state at those stages.
IRevertibleChangeTracking interface
The IRevertibleChangeTracking interface is designed to support the scenario where an object needs to be able to rollback to its previous state.
The interface has methods that mark when the object's current state should be made permanent or it should be reverted to the last known permanent state.
IEditableObject 用于短期、可恢复的修改,例如对话框。
IRevertibleChangeTracking 用于长期、可恢复的更改,例如编辑记录和跟踪记录是否需要保存。
我经常实现这两个接口,以便能够支持两个级别的撤消。
IEditableObject is used for short term, revertanble modifications such as dialog boxes.
IRevertibleChangeTracking is used for long-term, revertible changes such as editing a record and tracking whether or not the record needs to be saved.
I often implement both interfaces so that I have the ability to support two levels of undo.