Commit 2c955f2 1 parent 5c2d869 commit 2c955f2 Copy full SHA for 2c955f2
File tree 3 files changed +39
-6
lines changed
3 files changed +39
-6
lines changed Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
3
+ using EnvDTE ;
4
+ using EnvDTE80 ;
5
+
6
+ namespace CodeConverter . VsExtension
7
+ {
8
+ /// <summary>
9
+ /// http://www.wwwlicious.com/2011/03/29/envdte-getting-all-projects-html/#comment-2557459433
10
+ /// </summary>
11
+ public static class SolutionProjectExtensions
12
+ {
13
+ public static IEnumerable < Project > GetAllProjects ( this Solution sln )
14
+ {
15
+ return sln . Projects . Cast < Project > ( ) . SelectMany ( GetProjects ) ;
16
+ }
17
+
18
+ public static IEnumerable < Project > GetProjects ( this Project project )
19
+ {
20
+ if ( project . Kind == ProjectKinds . vsProjectKindSolutionFolder ) {
21
+ return project . ProjectItems . Cast < ProjectItem > ( )
22
+ . Select ( x => x . SubProject ) . Where ( x => x != null )
23
+ . SelectMany ( GetProjects ) ;
24
+ }
25
+ return new [ ] { project } ;
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -68,6 +68,11 @@ private static IEnumerable<T> GetSelectedSolutionExplorerItems<T>() where T: cla
68
68
var selectedObjects = ( IEnumerable < object > ) Dte . ToolWindows . SolutionExplorer . SelectedItems ;
69
69
var selectedItems = selectedObjects . Cast < UIHierarchyItem > ( ) . ToList ( ) ;
70
70
71
+ return ObjectOfType < T > ( selectedItems ) ;
72
+ }
73
+
74
+ private static IEnumerable < T > ObjectOfType < T > ( IReadOnlyCollection < UIHierarchyItem > selectedItems ) where T : class
75
+ {
71
76
var returnType = typeof ( T ) ;
72
77
return selectedItems . Select ( item => item . Object ) . Where ( returnType . IsInstanceOfType ) . Cast < T > ( ) ;
73
78
}
@@ -86,13 +91,12 @@ public static void SelectAll(this Window window)
86
91
87
92
public static IReadOnlyCollection < Project > GetSelectedProjects ( string projectExtension )
88
93
{
89
- var items = GetSelectedSolutionExplorerItems < Solution > ( )
90
- . SelectMany ( s => s . Projects . Cast < Project > ( ) )
91
- . Concat ( GetSelectedSolutionExplorerItems < Project > ( ) )
92
- . Concat ( GetSelectedSolutionExplorerItems < ProjectItem > ( ) . Where ( p => p . SubProject != null ) . Select ( p => p . SubProject ) )
94
+ var projects = GetSelectedSolutionExplorerItems < Solution > ( ) . SelectMany ( s => s . GetAllProjects ( ) )
95
+ . Concat ( GetSelectedSolutionExplorerItems < Project > ( ) . SelectMany ( p => p . GetProjects ( ) ) )
96
+ . Concat ( GetSelectedSolutionExplorerItems < ProjectItem > ( ) . Where ( p => p . SubProject != null ) . SelectMany ( p => p . SubProject . GetProjects ( ) ) )
93
97
. Where ( project => project . FullName . EndsWith ( projectExtension , StringComparison . InvariantCultureIgnoreCase ) )
94
- . ToList ( ) ;
95
- return items ;
98
+ . Distinct ( ) . ToList ( ) ;
99
+ return projects ;
96
100
}
97
101
98
102
public static IWpfTextViewHost GetCurrentViewHost ( IServiceProvider serviceProvider )
Original file line number Diff line number Diff line change 245
245
</Compile >
246
246
<Compile Include =" ConvertVBToCSCommand.cs" />
247
247
<Compile Include =" REConverterPackage.cs" />
248
+ <Compile Include =" SolutionProjectExtensions.cs" />
248
249
<Compile Include =" VisualStudioInteraction.cs" />
249
250
<Compile Include =" VsDocument.cs" />
250
251
</ItemGroup >
You can’t perform that action at this time.
0 commit comments