This project is read-only.

What should you use this for?

I use it in code that is not strictly used in production that is design time view models and tests. I found that I wanted to do stuff like this in tests quite a lot and I think this library may very well soon be extended to support extra functions for working with trees in test.

How to?

It's quite simple, write your pretty little tree in say a test:
const string structure = 

To parse this you need two things, a class to parse them into (which if you're using this you are likely to have) and then a factory method to create new instances of these using the extracted string and child elements:

var items = IntendationSplitter.SimpleTree.Parse(structure,
            delegate(string name, IEnumerable<MockTreeNode> children)
                    return new MockTreeNode(name) {Items = children.ToArray()};

That's how simple it is! And remember, since the constructor method gives you the text without indentation you can if you want extra behaviour have another parse function on top of this string if you wanted to encode multiple parameters to your object, say name|val1|val2 or something.

Putting it back again

I also found that for debugging purposes or simple exporting it is nice to be able to quick and dirty dump it back into the same format. To do that use the Format method:

var result = IndentationSplitter.SimpleTree.Format(items, i => i.Name, i => i.Items, "    ");

Last edited Jul 13, 2014 at 8:03 PM by Almund, version 2