Reputation: 153
I want to build C# binary decoder. I have XML file which is describing data structure of binary file.
Next step is dynamically making data structures (in code) based on that XML. Do you guys/girls have any comments, links, code, etc for me?
I am aware that this is general question, but I just want to start some where and I don't have clue from where.
EDIT:
Sorry need to remove code...
BR
Upvotes: 0
Views: 725
Reputation: 1424
Since you want to dynamically create the structures (rather than statically build classes based upon the XML definition), I guess you need a generic data structure which you can then query. What this looks like exactly would depend on what kind of data structures you're describing. Is it records and fields? Are there multiple record types in a hierarchy? If there's no hierarchy, you could just use a dictionary of key-value pairs for each field. If there is hierarchy, I'd have thought a navigable tree would cover most scenarios. You could use an XML DOM for this, but I think that's not the cleanest solution and I prefer to use generic tree structures. There isn't a built in one (see Tree data structure in C#), but it's fairly easy to create one with generics.
EDIT
The above assumes you want to dynamically create a structure to be used dynamically.
If you want to dymanically create a structure in code that will be used statically (e.g. you want to be able to write something like myDataStrucureThatWasDefinedInXml.MyProperty1
), have a look at CodeDom.
And having thought some more about it, it really depends on what you want to do once you've deserialized your binary data. You might also want to look at the Expando object and Expression Trees.
Upvotes: 1
Reputation: 1357
To read and write content of XML document you can use XmlDocument
class provided in C#.
Here are some links, which can help you:
Upvotes: 0