Okay, I've asked some questions before on SO about serializing, but I'm still stuck - so I figure I'll just spit out my entire case instead of sub-problems in the hope someone can point my nose in the right direction :)
My application is similar to Apple's "Quartz Composer", which means I have a tree-like structure of connected nodes.
Nodes are defined by an INode interface; actual node-types/classes are imported from DLL's using MEF, so node-types will not be known at compile time.
Nodes are connected, so bidirectional links can and will occur.
I'd like to save my 'composition' - the entire tree of nodes - to a file, preferably human-readable like XML. I really want to avoid saving to a proprietary format !
So what I need to serialize is :
a tree of objects, whose classes can be runtime imported (and thus not known beforehand), which can contain bidirectional links.
On top of that I'd like to store version information for the used node classes, so it's possible to tell if a 'composition' was stored using an older version of some node class than the used dll / node class in the current application.
Previously I was pointed at the DataContractSerializer, which seems like a nifty tool to store my tree and fully support the bidirectional links.
But if I want to serialize my tree (Interface IComposition), it starts complaining about unknown types - I have to specify each specific type it can encounter while serializing the tree...
And also there's no way for me to specify which assembly-version was used for a specific node-class.
Somehow it doesn't feel right to first enumerate my entire tree to find out which node-classes have been used, add these to a known-types list, and then serialize.
And even then, I'd have to find a way to add a section to the output-data specifying version information for used classes.
Maybe I'm the only one with this problem, but I really hope someone else has encountered and conquered this problem before - preferably with an elegant solution ;) I can imagine it's not something that can be handled by a standard .NET serializer, but maybe there's some 3rd-party (free, open source even ?) implementation ?