/// <summary> /// Create a node at the given location. /// </summary> /// <param name="parent">The parent root node</param> /// <param name="location">The location as access path.</param> /// <returns>The create node</returns> public Node Create(Node parent, string location) { var factory = new Codegen.Nodes.Factory(); var parts = location.Split(new char[] { '.' }); var path = new System.Text.StringBuilder(); Node result = null; foreach (var part in parts) { path.Append(part); var current = parent.GenGet(path.ToString()); if (current == null) { string nextsibling; current = factory.Create(part, out nextsibling); if (current == null) { return(null); } //All these nodes have been generated by a factory. //Mark them so that the generator can associate them to the first //parent having a location in the source file. current.SetFlag(Node.Flag.FactoryGeneratedNode, true, true); //Keep The insertion sequence ?? current.SetFlag(Node.Flag.FactoryGeneratedNodeKeepInsertionIndex, true, false); int index = 0; if (nextsibling != null) { var sibling = result.GenGet(nextsibling); index = sibling.Parent.IndexOf(sibling); } result.Add(current, index); } result = current; path.Append('.'); } return(result); }
private Node Create(Node node, string location) { var factory = new Codegen.Nodes.Factory(); var parts = location.Split(new char[] { '.' }); var path = new System.Text.StringBuilder(); Node result = null; foreach(var part in parts) { path.Append(part); var current = node.Get(path.ToString()); if (current == null) { string nextsibling; current = factory.Create(part, out nextsibling); if (current == null) return null; int index = 0; if (nextsibling != null) { var sibling = result.Get(nextsibling); index = sibling.Parent.IndexOf(sibling); } result.Add(current, index); } result = current; path.Append('.'); } return result; }