views:

35

answers:

3

I've got the hierarchial structure of files and folders inside of my application. Application works with absolute paths, which are stored in FileNode.Items list of strings.

When i've got to save my project, I serialize FileNode class in XML. But, I need to convert absolute paths to relatives (if possible) and then serialize.

So, my question is: Is there any solution to do it on the fly (i.e. any flag near the property which does any action with it) or i need to manually convert paths before every serialization and after every deserializaion?

Thank's a lot for your answers

+2  A: 

You could make a separate property on your FileNode class which returns relative paths, and add the [XmlIgnore] attribute to the original property to prevent it from being serialized.

Alternatively, you could implement IXmlSerializable to control the serialization yourself.

SLaks
+1  A: 

No, there's no automatic way to do that.

You can implement ISerializable or get your XML serialized object and make your paths relative through XmlDocument

Rubens Farias
A: 

I've got the idea to use [OnSerializingAttribute] and [OnDeserializingAttribute] to apply them to the methods, which convert paths to relative/full form. Is that gonna be alright?

xSeder
Please edit your question instead of adding an answer.
John Saunders