internal void RestoreSavedState() { if (m_stateStack.Count == 0) { return; } Dictionary <string, object> state = m_stateStack.Pop(); Type ct; for (ct = GetType(); ct != typeof(Robot); ct = ct.BaseType) { FieldInfo[] fields = ct.GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo field in fields) { if (field.DeclaringType != ct) { continue; } if (IsNotUndoableField(field)) { continue; } string name = ct.Name + "!" + field.Name; if (!state.ContainsKey(name)) { continue; } if (field.GetType().IsSubclassOf(typeof(Robot))) { Robot robo = (Robot)state[name]; robo.RestoreSavedState(); } else if (field.GetType().IsSubclassOf(typeof(IRobotList))) { IRobotList rl = (IRobotList)state[name]; rl.RestoreSavedState(); } else { field.SetValue(this, state[name]); } } } }
internal void SaveState() { Dictionary <string, object> state = new Dictionary <string, object>(); Type ct; for (ct = GetType(); ct != typeof(Robot); ct = ct.BaseType) { FieldInfo[] fields = ct.GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo field in fields) { if (field.DeclaringType != ct) { continue; } if (IsNotUndoableField(field)) { continue; } object value = field.GetValue(this); if (field.FieldType.IsSubclassOf(typeof(Robot))) { Robot robo = value as Robot; if (robo != null) { robo.SaveState(); } } else if (field.FieldType.IsSubclassOf(typeof(IRobotList))) { IRobotList rl = value as IRobotList; if (rl != null) { rl.SaveState(); } } else { string name = ct.Name + "!" + field.Name; state[name] = value; } } } m_stateStack.Push(state); }
public void EndEdit() { IRobotList irl = this; // C# is retarted. irl.CancelSavedState(); }
public void CancelEdit() { IRobotList irl = this; // C# is retarted. irl.RestoreSavedState(); }
public void BeginEdit() { IRobotList irl = this; // C# is retarted. irl.SaveState(); }