Monday, October 24, 2011

Silverlight Binary Serializer

It's never a good idea to rag on another developer for releasing open source software, and so this post does not intend to do that.

I was working on a project for Silverlight that required some serialization. I didn't love my options, XmlSerializer, DataContractSerializer, or Mike Talbot's Silverlight Serializer (http://whydoidoit.com/silverlight-serializer/).

Mike's serializer while in many ways quite good, is at times a bit inelegant for my tastes, and the performance is adequate but often not good enough.

These led me to the path of most/least resistance and I began working on my own. I made it a point not to rip off a single line of his code and as such even basic things are implemented radically differently.

Why you would want to use mine when Mike's is out there:

1. The ability to serialize/deserialize any .NET object (you may need to write a custom helper class for the serializer to do so).
2. Uses lambda expressions (emitting code) for high performance in certain scenarios (dictionary/list/property reflection).
3. Very compact payload and WCF helper class (see Payload) for serializing any object over WCF.

Valid reasons to continue to use Mike's:

1. He can serialize to XML and not just binary
2. You don't feel like changing code you've already written around Mikes Silverlight Serializer
3. ......?

Check it out: https://skydrive.live.com/?cid=f5dc6abbdb926c4f&sc=documents&id=F5DC6ABBDB926C4F%21116

The samples included show how to use this serializer in WCF, have the Serializer serialize complex types automagically (via reflection), and serialize another complex type which it serializes via a custom serializer.