Exemplo n.º 1
0
        // Internal function for parsing property paths. last_index provides
        // and index value for the last node name token, if supplied.
        protected static PropertyNode FindNode(PropertyNode current, List <PathComponent> components,
                                               int position, bool create)
        {
            // Run off the end of the list
            if (current == null)
            {
                return(null);
            }

            // Success! This is the one we want.
            else if (position >= components.Count)
            {
                return(current.GetAttribute(PropertyNode.Attribute.REMOVED) ? null : current);
            }

            // Empty component means root.
            else if (components[position].name == "")
            {
                return(FindNode(current.GetRootNode(), components, position + 1, create));
            }

            // . means current directory
            else if (components[position].name == ".")
            {
                return(FindNode(current, components, position + 1, create));
            }

            // .. means parent directory
            else if (components[position].name == "..")
            {
                PropertyNode parent = current.GetParent();
                if (parent == null)
                {
                    throw new Exception("Attempt to move past root with '..'");
                }
                else
                {
                    return(FindNode(parent, components, position + 1, create));
                }
            }

            // Otherwise, a child name
            else
            {
                PropertyNode child = current.GetChild(components[position].name,
                                                      components[position].index,
                                                      create);
                return(FindNode(child, components, position + 1, create));
            }
        }