开发者

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 seria开发者_如何学Clize 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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜