Microsoft.VisualStudio.Project.ProjectNode.AddDependentFileNode C# (CSharp) Method

AddDependentFileNode() protected method

This add methos adds the "key" item to the hierarchy, potentially adding other subitems in the process This method may recurse if the parent is an other subitem
If the parent node was found we add the dependent item to it otherwise we add the item ignoring the "DependentUpon" metatdata
protected AddDependentFileNode ( MSBuild.ProjectItem>.IDictionary subitems, string key ) : HierarchyNode
subitems MSBuild.ProjectItem>.IDictionary List of subitems not yet added to the hierarchy
key string Key to retrieve the target item from the subitems list
return HierarchyNode
        protected virtual HierarchyNode AddDependentFileNode(IDictionary<String, MSBuild.ProjectItem> subitems, string key)
        {
            if (subitems == null)
            {
                throw new ArgumentNullException("subitems");
            }

            MSBuild.ProjectItem item = subitems[key];
            subitems.Remove(key);

            HierarchyNode newNode;
            HierarchyNode parent = null;

            string dependentOf = item.GetMetadataValue(ProjectFileConstants.DependentUpon);
            Debug.Assert(String.Compare(dependentOf, key, StringComparison.OrdinalIgnoreCase) != 0, "File dependent upon itself is not valid. Ignoring the DependentUpon metadata");
            if (subitems.ContainsKey(dependentOf))
            {
                // The parent item is an other subitem, so recurse into this method to add the parent first
                parent = AddDependentFileNode(subitems, dependentOf);
            }
            else
            {
                // See if the parent node already exist in the hierarchy
                uint parentItemID;
                string path = Path.Combine(this.ProjectFolder, dependentOf);
                ErrorHandler.ThrowOnFailure(this.ParseCanonicalName(path, out parentItemID));
                if (parentItemID != (uint)VSConstants.VSITEMID.Nil)
                    parent = this.NodeFromItemId(parentItemID);
                Debug.Assert(parent != null, "File dependent upon a non existing item or circular dependency. Ignoring the DependentUpon metadata");
            }

            // If the parent node was found we add the dependent item to it otherwise we add the item ignoring the "DependentUpon" metatdata
            if (parent != null)
                newNode = this.AddDependentFileNodeToNode(item, parent);
            else
                newNode = this.AddIndependentFileNode(item);

            return newNode;
        }
ProjectNode