Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1.     public partial class store : IEditableObject
  2.     {
  3.         private Dictionary<string, object> backup = null;
  4.  
  5.         public void BeginEdit()
  6.         {
  7.             //TODO UNDERSTAND BELOW
  8.             //exit if in Edit mode
  9.             //uncomment if  CancelEdit discards changes since the
  10.             //LAST BeginEdit call is desired action
  11.             //otherwise CancelEdit discards changes since the
  12.             //FIRST BeginEdit call is desired action
  13.             //if (null != props) return;
  14.  
  15.             //enumerate properties
  16.  
  17.             PropertyInfo[] properties = (this.GetType()).GetProperties
  18.                 (BindingFlags.Public | BindingFlags.Instance);
  19.  
  20.             backup = new Dictionary<string,object>();
  21.  
  22.             for (int i = 0; i < properties.Length; i++)
  23.             {
  24.                 if (null != properties[i].GetSetMethod())
  25.                 {
  26.                     object value = properties[i].GetValue(this, null);
  27.                     backup.Add(properties[i].Name, value);
  28.                 }
  29.             }
  30.            
  31.     }
  32.         public void CancelEdit()
  33.         {
  34.             //check for inappropriate call sequence
  35.             if (null == backup) return;
  36.  
  37.             //retore old values
  38.  
  39.             PropertyInfo[] properties = (this.GetType()).GetProperties
  40.                 (BindingFlags.Public | BindingFlags.Instance);
  41.             for (int i = 0; i < properties.Length; i++)
  42.             {
  43.                 //check if there is a set accessor
  44.                 if (null != properties[i].GetSetMethod())
  45.                 {
  46.                     object value = backup[properties[i].Name];
  47.                     properties[i].SetValue(this, value, null);
  48.                 }
  49.             }
  50.             backup = null;
  51.         }
  52.  
  53.             public void EndEdit()
  54.             {
  55.                 backup = null;
  56.             }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement