Microsoft.VisualStudio.Project.FileNode.RenameChildNodes C# (CSharp) Method

RenameChildNodes() protected method

Rename all childnodes
protected RenameChildNodes ( FileNode parentNode ) : void
parentNode FileNode The newly added Parent node.
return void
        protected virtual void RenameChildNodes(FileNode parentNode)
        {
            foreach(HierarchyNode child in Children)
            {
                FileNode childNode = child as FileNode;
                if(null == childNode)
                {
                    continue;
                }
                string newfilename;
                if(childNode.HasParentNodeNameRelation)
                {
                    string relationalName = childNode.Parent.GetRelationalName();
                    string extension = childNode.GetRelationNameExtension();
                    newfilename = relationalName + extension;
                    newfilename = Path.Combine(Path.GetDirectoryName(childNode.Parent.GetMKDocument()), newfilename);
                }
                else
                {
                    newfilename = Path.Combine(Path.GetDirectoryName(childNode.Parent.GetMKDocument()), childNode.Caption);
                }

                childNode.RenameDocument(childNode.GetMKDocument(), newfilename);

                //We must update the DependsUpon property since the rename operation will not do it if the childNode is not renamed
                //which happens if the is no name relation between the parent and the child
                string dependentOf = childNode.ItemNode.GetMetadata(ProjectFileConstants.DependentUpon);
                if(!string.IsNullOrEmpty(dependentOf))
                {
                    childNode.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon, childNode.Parent.ItemNode.GetMetadata(ProjectFileConstants.Include));
                }
            }
        }