0

I am trying to figure out how to implement custom serialization/deserialization logic in a Silverlight app. In a standard .NET app, I can simply implement ISerializable to control how the object is serialized and provide the 'deserialization constructor' (SerializationInfo, StreamingContext) to handle the incoming data when deserializing.

Because ISerializable isn't supported in Silverlight, is there another way to accomplish this?

SonOfPirate
  • 5,642
  • 3
  • 41
  • 97
  • Maybe you have already looked into this as well, but apparently Marc Gravell [posted a question](http://stackoverflow.com/questions/6065081/using-a-custom-wcf-serializer-in-silverlight) on custom (WCF) serialization in Silverlight about a year ago (which also led to the blog post I have recently referred to). I do not know if it applies to your question, but there seems to be some kind of custom serialization support even for Silverlight in Marc's [protobuf-net](http://code.google.com/p/protobuf-net/) project as a result of the answer to his SO question – Anders Gustafsson Jun 18 '12 at 05:36
  • Yea, I'm not looking to replace the serializer. I am trying to find a way to implement the same capabilities to customize how a single type is serialized in SL just as we can in .NET using the ISerializable interface. I have no interest in changing how serialization in the larger sense is performed and replacing/changing/extending the serializer itself is way more than I need. – SonOfPirate Jun 18 '12 at 11:46
  • 1
    How 'custom' do you need it to be? There are some attributes that you can use to customize serialization that are available in Silverlight (you can lookup XmlElementAttribute for instance). – jv42 Jun 18 '12 at 16:58
  • Unfortunately, afik, none of the DataContractSerializers (Json, Net, Xml) respect the Xml attributes so that option doesn't help. A few of the scenarios I'm trying to work around are 1) deserializing into an immutable object, 2) deserializing into an object with read-only properties, or 3) deserializing from a single string that represents a complex data structure, for example, a Point that is serialized to a string such as "{X, Y, Z}" that needs to be deserialized into an object with X, Y and Z numeric properties. – SonOfPirate Jun 18 '12 at 18:45

0 Answers0