<FileTransferSettings> <UploadPath src='user'>C:\uploads</UploadPath> <DownloadPath src='app'>C:\downloads</DownloadPath> </FileTransferSettings>
I’d want to deserialize this XML into a FileTransferSettings object with 2 properties – UploadPath and DownloadPath. But I also want to preserve the src attribute for each property in a way that my code can interrogate it.
I think creating an associated UploadPathSrc and DownloadPathSrc property is a bit awkward and cumbersome.
Is there another way to represent this in .NET? To me, the src attribute seems like it should be treated as metadata. Is there a best practice for this?
(For background into why I’m trying to do this – see my previous question).
Thanks.
You could create a second class, FileTransferPath which had a string value ‘Path’ and an enum value ‘Source’
Then you could use code like
There might be better names you could choose for the class properties; I don’t know that I like the repetition of Path.
obj.Upload.Pathor something might be nicer.Note that you wouldn’t be able to directly serialize/deserialize this directly to and from the format you have using XmlSerialization; but it does accomplish what you need. (And you can still serialize to XML, you just have to do a little more work)