Click here to Skip to main content
Click here to Skip to main content

Fastest XML Serialization and Reflection Library

, 23 Mar 2012 CPOL
Rate this:
Please Sign up or sign in to vote.

The article and examples are in the zip file.

  Download - 2.7 MB



Quick Usage example:



           ReflectionPropertyCache cache = new ReflectionPropertyCache();
           ObjectInfo carInfo = cache.GetCachedObjectInfo(mycar, mycar.GetType());
           carInfo.propertyInfo[0].setter.dateTimeSetter(mycar, DateTime.Now);


  /// <summary>
       /// Serialization Example - Simple objects
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
       private void Example1Serialization()
            IPodConnector connector = new IPodConnector() { Version = "1.1a" };
                Screen screen = new Screen() { Size = "4 inch" };
                Stereo stereo = new Stereo() { Make = "alpine", Watts = "1000", };
                Car mycar = new Car() { brake = "5 piston", wheel = "22", Stereo = stereo, IPodConnector    =    connector };
        // Basic serialization example, raw with no attributes.
                StringBuilder XML1 = SerializerFacade.SerializeBasic(mycar);
                Car entityFromXml = SerializerFacade.Deserialize<Car>(XML1.ToString());



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Canada Canada
No Biography provided

Comments and Discussions

BugBug in your performance measuring code - serialization is fast but not as fast as shown Pinmemberhaindl23-Mar-12 2:23 
I think that your XML Serialization Library is very fast indeed.
But you have a bug in your performance measuring code.
In the method
XPathDebugger.CashFlowReports_Example.PerformanceTests.SerializationPerformance(ListBox listbox)
you first measure the round trip serialization performance of your SerializerFacade
Stopwatch watch = Stopwatch.StartNew();
for (int i = 0; i < testCount; ++i)
    entityFromXml =
listbox.Items.Add("\tRound trip serialization using TNT Ticks=" + watch.ElapsedTicks);
and then compare it to the .net-BCL XmlSerializer
Stopwatch watchNetXml = Stopwatch.StartNew();
for (int i = 0; i < testCount; ++i)
    StringWriter stringWriter = new StringWriter();
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(Car));
    xmlSerializer.Serialize(stringWriter, mycar);
    fromNetXML = DeserializeWithNet<Car>(stringWriter.ToString());
listbox.Items.Add("\tRound trip serialization using .Net Ticks=" + watchNetXml.ElapsedTicks);
The bug lies in the for-loop of the first measurement.
The watch.Stop(); should be done after the loop like watchNetXml.Stop(); and not inside.
The difference is that you measure your Serializer only 1 time, but the .net-BCL-Serializer 10 times.
Don't worry, your Serializer will still be the fastest though. Wink | ;)
But at my computer, the new measurement shows that your Serializer is actually about 5 times slower than shown in your screenshot.
Incorrectly before: about 300 ticks
Now correctly: about 1500 to 1600 ticks
It would be awesome if you could correct this bug and update your screenshot. Smile | :)
GeneralRe: Bug in your performance measuring code - serialization is fast but not as fast as shown Pinmemberrj4523-Mar-12 6:02 
QuestionArticle? PinmemberJustin Helsley22-Mar-12 9:26 
AnswerRe: Article? Pinmemberrj4522-Mar-12 9:44 
QuestionExpected more PinmvpMehdi Gholam22-Mar-12 7:03 
AnswerRe: Expected more Pinmemberrj4522-Mar-12 9:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 23 Mar 2012
Article Copyright 2012 by rj45
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid