Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class store : IEditableObject
- {
- private Dictionary<string, object> backup = null;
- public void BeginEdit()
- {
- //TODO UNDERSTAND BELOW
- //exit if in Edit mode
- //uncomment if CancelEdit discards changes since the
- //LAST BeginEdit call is desired action
- //otherwise CancelEdit discards changes since the
- //FIRST BeginEdit call is desired action
- //if (null != props) return;
- //enumerate properties
- PropertyInfo[] properties = (this.GetType()).GetProperties
- (BindingFlags.Public | BindingFlags.Instance);
- backup = new Dictionary<string,object>();
- for (int i = 0; i < properties.Length; i++)
- {
- if (null != properties[i].GetSetMethod())
- {
- object value = properties[i].GetValue(this, null);
- backup.Add(properties[i].Name, value);
- }
- }
- }
- public void CancelEdit()
- {
- //check for inappropriate call sequence
- if (null == backup) return;
- //retore old values
- PropertyInfo[] properties = (this.GetType()).GetProperties
- (BindingFlags.Public | BindingFlags.Instance);
- for (int i = 0; i < properties.Length; i++)
- {
- //check if there is a set accessor
- if (null != properties[i].GetSetMethod())
- {
- object value = backup[properties[i].Name];
- properties[i].SetValue(this, value, null);
- }
- }
- backup = null;
- }
- public void EndEdit()
- {
- backup = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement