forked from icsharpcode/CodeConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolutionProjectExtensions.cs
32 lines (29 loc) · 1.09 KB
/
SolutionProjectExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections.Generic;
using System.Linq;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
namespace ICSharpCode.CodeConverter.VsExtension;
/// <summary>
/// http://www.wwwlicious.com/2011/03/29/envdte-getting-all-projects-html/#comment-2557459433
/// </summary>
public static class SolutionProjectExtensions
{
public static IEnumerable<Project> GetAllProjects(this Solution sln)
{
ThreadHelper.ThrowIfNotOnUIThread();
return sln.Projects.Cast<Project>().SelectMany(GetProjects);
}
public static IEnumerable<Project> GetProjects(this Project project)
{
ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
if (project.Kind == ProjectKinds.vsProjectKindSolutionFolder) {
return project.ProjectItems.Cast<ProjectItem>()
.Select(x => x.SubProject).Where(x => x != null)
.SelectMany(GetProjects);
}
#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
return new[] { project };
}
}