Example #1
0
        private static void SerializeDeserializeXML()
        {
            var text =
                @"<Person Type=""GraphClimber.Program+Person, GraphClimber, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"">
  <Name Type=""System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"">Shani Elharrar</Name>
  <Age Type=""System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"">24</Age>
  <Surprise Type=""GraphClimber.Program+Person, GraphClimber, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"">
    <Name>null</Name>
    <Age Type=""System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"">23</Age>
    <Surprise Type=""System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"">4</Surprise>
  </Surprise>
</Person>";


            // Reader code:
            SlowGraphClimber <XmlReaderProcessor> climber2 =
                new SlowGraphClimber <XmlReaderProcessor>
                    (_stateMemberProvider);

            XElement reader = XElement.Parse(text);

            XmlReaderProcessor processor2 =
                new XmlReaderProcessor(reader);

            Person person2 = new Person();

            climber2.Climb(person2,
                           processor2);


            // Writer code:
            SlowGraphClimber <XmlWriterProcessor> climber =
                new SlowGraphClimber <XmlWriterProcessor>
                    (_stateMemberProvider);

            Person person = new Person()
            {
                Age      = 24,
                Name     = "Shani Elharrar",
                Surprise = new Person()
                {
                    Age      = 23,
                    Name     = null,
                    Surprise = 4
                }
            };

            XmlWriterProcessor processor = new XmlWriterProcessor();

            climber.Climb(person,
                          processor);
        }
Example #2
0
        public static void SerializeDeserializeStore()
        {
            var store = new TrivialStore();

            SlowGraphClimber <StoreWriterProcessor> climber = new SlowGraphClimber <StoreWriterProcessor>(_stateMemberProvider);

            var processor = new StoreWriterProcessor(store);
            var box       = new StrongBox <Person>(GetPerson());

            climber.Climb(box, processor);


            SlowGraphClimber <StoreReaderProcessor> readerClimber = new SlowGraphClimber <StoreReaderProcessor>(_stateMemberProvider);

            var readerProcessor = new StoreReaderProcessor(store);
            var readBox         = new StrongBox <object>(null);

            readerClimber.Climb(readBox, readerProcessor);
        }