Beispiel #1
0
        public void WriteProjectItemChildren(string projectItemPath, IFileProcessor processor)
        {
            ProjectItem parentProjectItem = RetrieveProjectItem(projectItemPath);

            if (parentProjectItem == null)
            {
                throw new InvalidOperationException("Could not create a project item from the path '" + projectItemPath + ".");
            }

            List <ProjectItem> previousItems = new List <ProjectItem>();
            List <ProjectItem> currentItems  = new List <ProjectItem>();

            foreach (ProjectItem item in parentProjectItem.ProjectItems)
            {
                previousItems.Add(item);
            }

            foreach (GeneratedObject genedClass in processor.GenerateObjects())
            {
                string fileName = genedClass.Name.ToPascalCase() + DefaultExtension;
                string path     = Path.Combine(projectItemPath.Substring(0, projectItemPath.LastIndexOf(Path.DirectorySeparatorChar)), fileName);

                WriteProjectFile(Messages.FileHeader(projectItemPath) + genedClass.Content, path);

                ProjectItem previousItem = previousItems.Find(p => p.Name == Path.GetFileName(path));
                currentItems.Add(previousItem == default(ProjectItem) ? parentProjectItem.ProjectItems.AddFromFile(path) : previousItem);
            }

            DeleteRemovedItems(parentProjectItem, currentItems);
        }