Greycastle Logo

IndentationSplitter

Time for an update about my recent ventures. I’ve just now uploaded my very first public Codeplex and Nuget package! Yay!

It’s called IndentationSplitter and gives right now you a single class called SimpleTree. This class has two methods, Format and Parse. Very simplistic but in my opinion quite useful.

See I constantly find myself rewriting some code snippets for either outputting a code object tree into text to be able to validate it in unit tests or the other way around, trying to build up a tree of objects which always generates a shitload (excuse the expression) of text. Take the following for example:

var items = new [] {
    new MockTreeNode ("item1") {
        Items = new MockTreeNode[] {
                    new MockTreeNode ("item1.1"),
                    new MockTreeNode ("item1.2") {
                Items = new MockTreeNode[] {
                    new MockTreeNode ("item1.2.1"),
                    new MockTreeNode ("item1.2.2"),
                }
            },
            new MockTreeNode ("item1.3"),
        }
    },
    new MockTreeNode ("item2") {
        Items = new MockTreeNode[] {
            new MockTreeNode ("item2.1"),
            new MockTreeNode ("item2.2")
        }
    }
};

Wouldn’t it be nicer to write this in a small string instead? Maybe like this:

const string designTimeChecks = @"if value is something
    check-regex value is something
    check service is running
    if registry value is something
        check-file exists here
    if registry value is something else
        check-file is in this place
if value is something else
    check-registry";

SpecificationItems = SimpleTree.Parse<ISpecificationItemViewModel> (designTimeChecks, GetSpecItemViewModel);

Which is exactly what you can do with this package.

It’s not like walking on water or moving mountains but I think it can be useful if applied in the right places. As I summarized, in the beginning, this is meant to be a general-purpose tool for helping to reduce code amount (aka complexity) and increase readability without you having to have all the bulky code for that adding to your already increasing number of lines of code. I think that putting this in a separate Nuget package makes it even more useful since it doesn’t interfere with the rest of your code.

Anyway, I hope it’ll help someone out there in the meantime I’ll use it to my heart’s content 🙂 And also, I spent a few hours on this project just because I needed it for a design-time view model in the unTroublemaker, coming soon..

© 2024 Greycastle