예제 #1
0
        [TestMethod] public void TestPersistenceBasics()
        {
            XmlSerializationContext xsc = new XmlSerializationContext();

            MyTestObject mto2 = new MyTestObject("Gary", 3.1, null);

            MyTestObject mto = new MyTestObject("Bill", 6.2,
                                                new MyTestObject("Bob", 12.4,
                                                                 new MyTestObject("Steve", 24.8,
                                                                                  new MyTestObject("Dave", 48.1,
                                                                                                   new MyTestObject("Sally", 96.2,
                                                                                                                    new MyTestObject("Rufus", 186.9,
                                                                                                                                     null))))));

            Debug.WriteLine("Setting " + mto.Child1.Child1.Name + "'s child2 to " + mto2.Name);
            mto.Child1.Child1.Child2 = mto2;
            Debug.WriteLine("Setting " + mto.Child1.Name + "'s child2 to " + mto2.Name);
            mto.Child1.Child2 = mto2;

            xsc.StoreObject("MTO", mto);

            xsc.Save(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "foo.xml");

            xsc.Reset();

            xsc.Load(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "foo.xml");

            MyTestObject mto3 = (MyTestObject)xsc.LoadObject("MTO");

            xsc = new XmlSerializationContext();
            xsc.StoreObject("MTO", mto3);
            xsc.Save(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "foo2.xml");
        }
예제 #2
0
 public void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     m_child1   = (MyTestObject)xmlsc.LoadObject("Child1");
     m_child2   = (MyTestObject)xmlsc.LoadObject("Child2");
     m_name     = (string)xmlsc.LoadObject("Name");
     m_age      = (double)xmlsc.LoadObject("Age");
     m_married  = (bool)xmlsc.LoadObject("Married");
     m_birthday = (DateTime)xmlsc.LoadObject("Birthday");
     m_ts       = (TimeSpan)xmlsc.LoadObject("TimeSpan");
     m_ht       = (Hashtable)xmlsc.LoadObject("Hashtable");
     m_al       = (ArrayList)xmlsc.LoadObject("ArrayList");
 }
예제 #3
0
        public MyTestObject(string name, double age, MyTestObject child)
        {
            m_name   = name;
            m_age    = age;
            m_child1 = child;
            Random random = new Random();

            m_married  = random.NextDouble() < 0.5;
            m_birthday = DateTime.Now - TimeSpan.FromTicks((long)(random.NextDouble() * TimeSpan.FromDays(20).Ticks));
            m_ts       = TimeSpan.FromTicks((long)(random.NextDouble() * TimeSpan.FromDays(20).Ticks));
            m_ht       = new Hashtable();
            m_ht.Add("Age", m_age);
            m_ht.Add("Birthday", m_birthday);
            m_al.Add("Dog");
            m_al.Add("Cat");
            m_al.Add("Cheetah");
            m_al.Add("Banana");
            m_al.Add("Which one of these is not like the others?");
        }