Desktop/Mobile Serialization
-
Hi, I have a class hierarchy of objects representing typical stuff like employees, users, addresses and so on. I've defined the relationships, created a database and now want to add serialization. The top-most class is an abstract one, kind of like
CObject
I suppose and my objects may exist on a desktop or mobile platform. I started to implement custom serialization but the Compact Framework doesn't support it so now I have to write my own stuff. What I'm looking for is some ideas as to how best to implement serialization for my system. Typically, each object will need to be serialized to/from my database and to/from a web service so I'm guessing I just need to write some methods to serialize to XML and/or to aMemoryStream
object. OK, assuming that's the way to implement the actual serialization, how best to define it within my hierarchy? I was thinking of two virtual methods,toXML()
andfromXML()
defined withing my top-most class and an abstract method calledgetObjectData()
which all descendents *must* implement.toXML();
toMS();
getObjectData();Within
toXML()
andtoMS()
, there's a call togetObjectData()
which gets the object data ready to be formatted into aMemoryStream
object or XML. Each object would also implement a constructor accepting an XML orMemoryStream
object but I'm very new to C# so I don't know if there's a way of forcing derived classes to implement these constructors or whether I "should" or not. What do you think? Any help much appreciated including book/article suggestions :)