Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void BeginEdit()
        {
            IRobotList irl = this; // C# is retarted.

            irl.SaveState();
        }