using System.Collections.Generic;
public class IndexedTree {
private readonly IDictionary<string, IndexedTree> _me;
private readonly string _splitKey = ".";
public IndexedTree this[string key] {
public object Value { get; set; }
public void Add(string dottedItem) {
if ( string.IsNullOrWhiteSpace( dottedItem ) ) {
throw new ArgumentException("dottedItem cannot be empty");
if ( (index = dottedItem.IndexOf( _splitKey ) ) < 0 ) {
throw new ArgumentException("dottedItem didn't contain " + _splitKey);
string key = dottedItem.Substring(0, index), rest = dottedItem.Substring(index + 1);
if (_me.ContainsKey(key)) {
child = new IndexedTree( _splitKey );
if (rest.IndexOf(_splitKey) >= 0) {
public IndexedTree(string splitKey) {
_me = new Dictionary<string, IndexedTree>();
public static void Main()
IndexedTree tree = new IndexedTree(".");
tree.Add("Level1.Level2.Level3.Item");
tree.Add("Level1.Level2.Value");
Console.WriteLine(tree["Level1"]["Level2"].Value);
Console.WriteLine(tree["Level1"]["Level2"]["Level3"].Value);