xSeder
xSeder

Reputation: 535

Modify data while serializing

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

Upvotes: 1

Views: 143

Answers (2)

Rubens Farias
Rubens Farias

Reputation: 57946

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

Upvotes: 1

SLaks
SLaks

Reputation: 887433

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.

Upvotes: 2

Related Questions