当前位置: 首页>>代码示例>>C#>>正文


C# ProjectItems.Cast方法代码示例

本文整理汇总了C#中ProjectItems.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectItems.Cast方法的具体用法?C# ProjectItems.Cast怎么用?C# ProjectItems.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProjectItems的用法示例。


在下文中一共展示了ProjectItems.Cast方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAllProjects

        private static IEnumerable<Project> GetAllProjects(ProjectItems projectItems)
        {
            if(projectItems == null)
                yield break;

            foreach(var projectItem in projectItems.Cast<ProjectItem>())
            {
                if(projectItem.SubProject != null)
                {
                    yield return projectItem.SubProject;

                    foreach(var project in GetAllProjects(projectItem.SubProject))
                    {
                        yield return project;
                    }
                }
                else
                {
                    foreach(var project in GetAllProjects(projectItem.ProjectItems))
                    {
                        yield return project;
                    }
                }
            }
        }
开发者ID:HansKindberg-Lab,项目名称:VisualStudio-Templates,代码行数:25,代码来源:SolutionExtension.cs

示例2: foreach

 private static List<ProjectItem>Get(ProjectItems projectItems)
 {
     var items = new List<ProjectItem>();
     foreach (var projectItem in projectItems.Cast<ProjectItem>())
     {
         items.Add(projectItem);
         items.AddRange(Get(projectItem.ProjectItems));
     }
     return items;
 }
开发者ID:Gemkin,项目名称:CrossBase,代码行数:10,代码来源:CSharpSolutionParser.cs

示例3: DeleteGeneratedFilesInProjectItems

 private static List<ProjectItem> DeleteGeneratedFilesInProjectItems(ProjectItems projectItems)
 {
     var items = new List<ProjectItem>();
     foreach (var projectItem in projectItems.Cast<ProjectItem>())
     {
         try
         {
             items.AddRange(DeleteGeneratedFilesInProjectItems(projectItem.ProjectItems));
             if (projectItem.FileNames[0].EndsWith(".g.cs"))
                 items.Add(projectItem);
         }
         catch (Exception)
         {
         }
     }
     return items;
 }
开发者ID:Gemkin,项目名称:CrossBase,代码行数:17,代码来源:CSharpSolutionParser.cs

示例4: VisitPath

        private bool VisitPath(ICollection<ProjectItem> path, string itemname, ProjectItems projectItems)
        {
            if (projectItems == null || projectItems.Count == 0)
            {
                return false;
            }

            if (projectItems.Cast<ProjectItem>().Any(i => i.Name == itemname))
            {
                return !(projectItems.Parent is Project);
            }

            foreach (ProjectItem projectItem in projectItems)
            {
                if  (VisitPath(path, itemname, projectItem.ProjectItems))
                {
                    path.Add(projectItem);
                    return true;
                }
            }

            return false;
        }
开发者ID:MonsterCoder,项目名称:MavenThought.VSExtension,代码行数:23,代码来源:AddSpecificationCommand.cs

示例5: CopyTemplates

        public static void CopyTemplates(DTE dte, string templatesFolderName, string netVersion, string toolsPath, string vsVersion, out string templatesFolder, out HashSet<string> existingTTIncludes, out ProjectItems templatesProjectItems)
        {
            var slnFolder = Path.GetDirectoryName(dte.Solution.FullName);
            templatesFolder = Path.Combine(slnFolder, templatesFolderName);
            if (!Directory.Exists(templatesFolder))
            {
                Directory.CreateDirectory(templatesFolder);
            }

            const string solutionItemsFolderName = "Solution Items";
            Project solutionItems = dte.Solution.Projects.OfType<Project>().FirstOrDefault(pi => pi.Name == solutionItemsFolderName);
            UIHierarchyItem solutionItemsUIHierarchyItem = null;
            Action setSolutionItemsUIHierarchyItem = () => solutionItemsUIHierarchyItem = (dte.Windows.Cast<Window>().First(w => w.Type == vsWindowType.vsWindowTypeSolutionExplorer).Object as UIHierarchy)?.UIHierarchyItems.Cast<UIHierarchyItem>().First().UIHierarchyItems.Cast<UIHierarchyItem>().First(uihi => uihi.Name == solutionItemsFolderName);
            bool solutionItemsExpanded;

            Project templates = null;
            UIHierarchyItem templatesUIHierarchyItem = null;
            Action setTemplatesUIHierarchyItem = () => templatesUIHierarchyItem = solutionItemsUIHierarchyItem.UIHierarchyItems.Cast<UIHierarchyItem>().First(uihi => uihi.Name == templatesFolderName);
            bool templatesItemsExpanded = false;
            Action addTemplatesUIHierarchyItem = () =>
            {
                templates = ((EnvDTE80.SolutionFolder)solutionItems.Object).AddSolutionFolder(templatesFolderName);
                setTemplatesUIHierarchyItem();
                templatesItemsExpanded = false;
            };

            if (solutionItems == null)
            {
                solutionItems = ((EnvDTE80.Solution2)dte.Solution).AddSolutionFolder(solutionItemsFolderName);
                setSolutionItemsUIHierarchyItem();
                solutionItemsExpanded = false;
                addTemplatesUIHierarchyItem();
            }
            else
            {
                setSolutionItemsUIHierarchyItem();
                solutionItemsExpanded = solutionItemsUIHierarchyItem.UIHierarchyItems.Expanded;

                templates = ((IEnumerable)solutionItems.ProjectItems).Cast<ProjectItem>().FirstOrDefault(pi => pi.Name == templatesFolderName).SubProject;
                if (templates == null)
                {
                    addTemplatesUIHierarchyItem();
                }
                else
                {
                    setTemplatesUIHierarchyItem();
                    templatesItemsExpanded = templatesUIHierarchyItem.UIHierarchyItems.Expanded;
                }
            }

            var ttincludesFolder = Path.Combine(toolsPath, "ttincludes");
            templatesProjectItems = (ProjectItems)templates.ProjectItems;
            existingTTIncludes = new HashSet<string>(templatesProjectItems.Cast<ProjectItem>().Select(pi => pi.Name));
            string ttIncludeName = null;
            foreach (var ttInclude in Directory.GetFiles(ttincludesFolder).Where(f => (ttIncludeName = Path.GetFileName(f)).StartsWith("WAQS.")))
            {
                AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems);
            }
            var ttIncludesFolderVS = Path.Combine(ttincludesFolder, vsVersion);
            foreach (var ttInclude in Directory.GetFiles(ttIncludesFolderVS).Where(f => (ttIncludeName = Path.GetFileName(f)).StartsWith("WAQS.")))
            {
                AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems);
            }
            const string mergeTTIncludeFileName = "MergeT4Files.ttinclude";
            File.Copy(Path.Combine(ttincludesFolder, mergeTTIncludeFileName), Path.Combine(templatesFolder, mergeTTIncludeFileName), true);
            var specialMergeFolder = Path.Combine(ttincludesFolder, "SpecialMerge");
            foreach (var specialMerge in Directory.GetFiles(specialMergeFolder))
            {
                var ttSpecialMergeFileName = Path.GetFileName(specialMerge);
                var specialMergeFile = Path.Combine(specialMergeFolder, ttSpecialMergeFileName);
                var ttSpecialMergeFileCopy = Path.Combine(templatesFolder, ttSpecialMergeFileName);
                File.Copy(specialMergeFile, ttSpecialMergeFileCopy, true);
                if (!existingTTIncludes.Contains(ttSpecialMergeFileName))
                {
                    templatesProjectItems.AddFromFile(ttSpecialMergeFileCopy);
                }
            }
            try
            {
                templatesUIHierarchyItem.UIHierarchyItems.Expanded = templatesItemsExpanded;
                solutionItemsUIHierarchyItem.UIHierarchyItems.Expanded = solutionItemsExpanded;
            }
            catch
            {
            }
            MergeTTIncludes(dte, templates, templatesFolder);
        }
开发者ID:bnjMichel,项目名称:waqs,代码行数:87,代码来源:TemplatesCopying.cs

示例6: RemoveFilesAndFolders

        /// <summary>
        /// Removes the files and folders.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="targetProjectType">Type of the target project.</param>
        /// <param name="levels">The number of levels to walk down the chain. If <c>-1</c>, it will handle all levels.</param>
        /// <param name="fileFilter">An enumerable of files that should be handled with care, can be <c>null</c>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="source" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="target" /> is <c>null</c>.</exception>
        private void RemoveFilesAndFolders(ProjectItems source, ProjectItems target, ProjectType targetProjectType, int levels, IEnumerable<string> fileFilter)
        {
            Argument.IsNotNull("source", source);
            Argument.IsNotNull("target", target);

            if (fileFilter == null)
            {
                fileFilter = new string[] { };
            }

            string targetParentName = target.Parent.GetObjectName();

            Log.Debug("Removing files and folders from target '{0}'", targetParentName);

            if (levels == 0)
            {
                return;
            }

            levels--;

            // Yep, this is right, we start at 1... :(
            for (int i = 1; i < target.Count + 1; i++)
            {
                var targetItem = target.Item(i);

                if (ShouldSkipRemovingOfItem(source.ContainingProject, targetItem, targetProjectType))
                {
                    Log.Debug("Skipping item '{0}' because it is ignored by a rule for target project {1}", targetItem.GetObjectName(), targetProjectType);
                    continue;
                }

                var existingSourceItem = (from sourceItem in source.Cast<ProjectItem>() where string.Equals(targetItem.Name, sourceItem.Name, StringComparison.InvariantCultureIgnoreCase) select sourceItem).FirstOrDefault();

                if (existingSourceItem != null && !fileFilter.Any(x => string.Equals(x, targetItem.GetNameRelativeToRoot(), StringComparison.InvariantCultureIgnoreCase)))
                {
                    // Check if the item should be removed (when the item should not be added as linked file, then we should remove it)
                    if (!ShouldSkipAddingOfItem(existingSourceItem, targetProjectType))
                    {
                        RemoveFilesAndFolders(existingSourceItem.ProjectItems, targetItem.ProjectItems, targetProjectType, levels, fileFilter);
                        continue;
                    }

                    Log.Debug("Found linked file '{0}' that is now ignored by a rule, removing it", targetItem.FileNames[0]);
                }

                // Get it once, we don't want to retrieve this several times
                var relatedProjects = source.ContainingProject.GetRelatedProjects(false);

                if (targetItem.IsFolder())
                {
                    RemoveNestedItems(targetItem.ProjectItems, relatedProjects);

                    if (targetItem.ProjectItems.Count == 0)
                    {
                        Log.Debug("Removing folder '{0}' because it no longer contains items", targetItem.Name);

                        targetItem.Remove();
                        i--;
                    }
                }
                else
                {
                    // If this is a linked file and not an actual file in another related project, remove it
                    if (targetItem.IsLinkedFile() && !targetItem.IsActualFileInAnyRelatedProject(relatedProjects))
                    {
                        Log.Debug("Removing file '{0}' because it is a linked file to the root project", targetItem.FileNames[0]);

                        targetItem.Remove();
                        i--;
                    }
                }
            }

            Log.Debug("Removed files and folders from target '{0}'", targetParentName);
        }
开发者ID:GeertvanHorrik,项目名称:Caitlyn,代码行数:86,代码来源:Linker.cs

示例7: Items

 static IEnumerable<ProjectItem> Items(ProjectItems ProjectItems)
 {
     return ProjectItems.Cast<ProjectItem>().SelectMany(Items);
 }
开发者ID:ericbock,项目名称:raconteur,代码行数:4,代码来源:ProjectEx.cs

示例8: NavigateProjectItems

 private void NavigateProjectItems(ProjectItems items, List<ProjectItem> xibs)
 {
     if (items == null) return;
     items.Cast<ProjectItem>().ToList().ForEach(pi =>
     {
         if (pi.SubProject != null) FindXibs(pi.SubProject, xibs);
     });
 }
开发者ID:csteeg,项目名称:VSMonoTouch,代码行数:8,代码来源:VSMonoTouchPackage.cs

示例9: AddFolder

        /// <summary>
        /// Adds a folder to a specified <paramref name="collection" /> of project items.
        /// </summary>
        /// <param name="collection">
        /// A <see cref="ProjectItems" /> collection that belongs to a <see cref="Project" /> or
        /// <see cref="ProjectItem" /> of type <see cref="EnvDTE.Constants.vsProjectItemKindPhysicalFolder" />.
        /// </param>
        /// <param name="folderName">
        /// Name of the folder to be added.
        /// </param>
        /// <param name="basePath">
        /// Absolute path to the directory where the folder is located.
        /// </param>
        /// <returns>
        /// A <see cref="ProjectItem" /> that represents new folder added to the <see cref="Project" />.
        /// </returns>
        /// <remarks>
        /// If the specified folder doesn't exist in the solution and the file system,
        /// a new folder will be created in both. However, if the specified folder
        /// already exists in the file system, it will be added to the solution instead.
        /// Unfortunately, an existing folder can only be added to the solution with
        /// all of sub-folders and files in it. Thus, if a single output file is
        /// generated in an existing folders not in the solution, the target folder will
        /// be added to the solution with all files in it, generated or not. The
        /// only way to avoid this would be to immediately remove all child items
        /// from a newly added existing folder. However, this could lead to having
        /// orphaned files that were added to source control and later excluded from
        /// the project. We may need to revisit this code and access <see cref="SourceControl" />
        /// automation model to remove the child items from source control too.
        /// </remarks>
        private static ProjectItem AddFolder(ProjectItems collection, string folderName, string basePath)
        {
            // Does the folder already exist in the solution?
            ProjectItem folder = collection.Cast<ProjectItem>().FirstOrDefault(p => string.Equals(p.Name, folderName, StringComparison.OrdinalIgnoreCase));
            if (folder != null)
            {
                return folder;
            }

            try
            {
                // Try adding folder to the project.
                // Note that this will work for existing folder in a Database project but not in C#.
                return collection.AddFolder(folderName);
            }
            catch (COMException)
            {
                // If folder already exists on disk and the previous attempt to add failed
                string folderPath = Path.Combine(basePath, folderName);
                if (Directory.Exists(folderPath))
                {
                    // Try adding it from disk
                    // Note that this will work in a C# but is not implemented in Database projects.
                    return collection.AddFromDirectory(folderPath);
                }

                throw;
            }
        }
开发者ID:icool123,项目名称:T4Toolbox,代码行数:59,代码来源:OutputFileManager.cs

示例10: CreateTestProjectItem

        protected ProjectItem CreateTestProjectItem(ProjectItems projectItems, string templateName)
        {
            if (projectItems == null)
            {
                throw new ArgumentNullException("projectItems");
            }

            string templateFile = Solution.GetProjectItemTemplate(templateName, this.TargetProject.Language);
            string itemName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            ProjectItem projectItem = projectItems.AddFromTemplate(templateFile, itemName)
                ?? projectItems.Cast<ProjectItem>().First(pi => Path.GetFileNameWithoutExtension(pi.Name) == itemName);
            projectItem.Document.Close(); // To avoid sideffects and enable testing by writing to files as opposed to document manipulation
            return projectItem;
        }
开发者ID:icool123,项目名称:T4Toolbox,代码行数:14,代码来源:IntegrationTest.cs

示例11: ParseProjectItems

        private void ParseProjectItems(ProjectItems projectItems)
        {
            if (projectItems == null)
                return;
            WriteLine("ParseProjectItems " + projectItems.Count);

            foreach (var item in projectItems.Cast<ProjectItem>())
            {
                ParseProjectItem(item);
            }
        }
开发者ID:Gemkin,项目名称:CrossBase,代码行数:11,代码来源:CSharpSolutionParser.cs


注:本文中的ProjectItems.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。