How could I define a simple hierarchy in some easy to read format and then iterate/navigate through it in C#?
I imagine I could just define a set of classes and get the properties, but I would rather use a less code-looking format, something xml-ish or even plain text – for example..
<root>
<level1 name="whatever">
<sublevel1 />
<sublevel2 />
</level1>
<level2 />
<level3 />
</root>
or maybe something the asp.net MVC model binder just made me think of
Root.Name=Thing
Root.Type=Object
Root.SubLevel[0].Name=SomeItems
Root.SubLevel[0].Type=Collection
Root.SubLevel[1].Name=OtherThing
Root.SubLevel[1].Type=Object
Root.SubLevel[1].SubLevel[0].Name=OtherItems
Root.SubLevel[1].SubLevel[0].Type=Collection
Anyway, the simpler the better. The idea would be to iterate through the hierarchy and repeat various actions using its properties – like “Name”, “Type”, etc. I would also like to be able to use the index (in the second example) or just be able to keep track of my position in the structure while navigating through it. How can this be done other than modeling it with classes?
XML is the obvious choice as it is both perfectly suited for hierarchies and there is great support for reading it in C# (especially via System.Xml.Linq.XDocument).
If you really want an alternative, without knowing why, I would suggest looking at YAML: http://en.wikipedia.org/wiki/Yaml