private Dictionary<object, SchemaProperty> CreatePropertiesDictionary()
{
// Search up the tree until a schema is found with a populated properties hashtable,
// while keeping a list of the transitions.
var addTransitions = new Stack<KeyValuePair<object, SchemaProperty>>();
var node = this;
while (node != null)
{
if (node.properties == null)
{
// The schema is the same as the parent schema except with the addition of a single
// property.
addTransitions.Push(new KeyValuePair<object, SchemaProperty>(
node.addPropertyTransitionInfo.Key,
new SchemaProperty(node.NextValueIndex - 1, node.addPropertyTransitionInfo.Attributes)));
}
else
{
// The schema has a populated properties hashtable - we can stop here.
break;
}
node = node.parent;
}
if (node == null)
throw new InvalidOperationException("Internal error: no route to a populated schema was found.");
// Add the properties to the hashtable in order.
var result = new Dictionary<object, SchemaProperty>(node.properties);
while (addTransitions.Count > 0)
{
var keyValuePair = addTransitions.Pop();
result.Add(keyValuePair.Key, keyValuePair.Value);
}
return result;
}