如何获取引用特定迭代路径的查询名称

使用选定的项目名称,我加载了迭代路径。 现在我需要获取引用所选迭代路径的查询名称。

用于加载传递项目名称的迭代路径的代码:

private void LoadIterationPaths(string projectName) { var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(_tfs.Uri); var wiStore = tfs.GetService(); var projCollections = wiStore.Projects; var detailsOfTheSelectedProject = projCollections.Cast().Where(project => !String.IsNullOrEmpty(_selectedTeamProject.Name)) .FirstOrDefault(project => project.Name.Contains(_selectedTeamProject.Name)); var iterationPathsList = GetIterationPaths(detailsOfTheSelectedProject); foreach (var iterationPath in iterationPathsList.Where(iterationPath => iterationPath.Contains(projectName))) { cmbIterationPath.Items.Add(iterationPath); } cmbIterationPath.Enabled = cmbIterationPath.Items.Count > 0; } 

现在,我需要获取引用所选迭代路径的查询名称列表。 谢谢。

注意 :我能够获得项目中的所有查询名称,但我不需要。 为此,我使用了以下代码

 foreach (StoredQuery qi in detailsOfTheSelectedProject.StoredQueries) { cmbQueries.Items.Add(qi.Name); } 

您的代码应如下所示

string selectedIterationPath = ... foreach (StoredQuery qi in detailsOfTheSelectedProject.StoredQueries) { if (qi.QueryText.Contains(selectedIterationPath) { cmbQueries.Items.Add(qi.Name); } }

这就是我和Beytan Kurt在评论中提出的建议。 而不是哑Contains ,你应该使用正则表达式来解释误报和否定。