private static (LabeledArrayTreeNodeBuilder <TypeContext> builder, bool created) GetOrCreateBuilder( Dictionary <NodePath, LabeledArrayTreeNodeBuilder <TypeContext> > dict, NodePath path) { if (dict.TryGetValue(path, out var typeCollectionBuilder)) { return(typeCollectionBuilder, false); } var builder = new LabeledArrayTreeNodeBuilder <TypeContext>(path); dict.Add(path, builder); return(builder, true); }
private static void UpdateParentCollections( Dictionary <NodePath, LabeledArrayTreeNodeBuilder <Type> > dict, LabeledArrayTreeNodeBuilder <Type> builder) { var parentPath = builder.Path.GetParentPath(); if (parentPath == null) { return; } var(parentBuilder, parentCreated) = GetOrCreateBuilder(dict, parentPath.Value); parentBuilder.TryAddOwnedCollection(builder); if (parentCreated) { UpdateParentCollections(dict, parentBuilder); } }
private static void UpdateParentCollections( Dictionary <NodePath, LabeledArrayTreeNodeBuilder <TypeContext> > dict, LabeledArrayTreeNodeBuilder <TypeContext> builder) { var parentPath = builder.Path.GetParentPath(); if (parentPath == null) { return; } var(parentBuilder, parentCreated) = GetOrCreateBuilder(dict, parentPath.Value); parentBuilder.TryAddOwnedCollection(builder); // Check if it is necessary to create parent nodes till root is reached. if (parentCreated) { UpdateParentCollections(dict, parentBuilder); } }