File tree Expand file tree Collapse file tree 3 files changed +44
-29
lines changed Expand file tree Collapse file tree 3 files changed +44
-29
lines changed Original file line number Diff line number Diff line change @@ -47,34 +47,5 @@ public static async Task<IEnumerable<object>> RegisterCommandsAsync(this AsyncPa
4747 }
4848 return commands ;
4949 }
50-
51- /// <summary>
52- /// Automatically calls the <see cref="BaseToolWindow{T}.Initialize(ToolkitPackage)"/> method for every BaseToolWindow<> in the package or provided assemblies.
53- /// </summary>
54- /// <param name="package"></param>
55- /// <param name="assemblies"></param>
56- /// <returns></returns>
57- public static void RegisterToolWindows ( this AsyncPackage package , params Assembly [ ] assemblies )
58- {
59- List < Assembly > assembliesList = assemblies . ToList ( ) ;
60- Assembly packageAssembly = package . GetType ( ) . Assembly ;
61- if ( ! assembliesList . Contains ( packageAssembly ) )
62- assembliesList . Add ( packageAssembly ) ;
63-
64- Type baseToolWindowType = typeof ( BaseToolWindow < > ) ;
65- IEnumerable < Type > toolWindowTypes = assembliesList . SelectMany ( x => x . GetTypes ( ) )
66- . Where ( x =>
67- ! x . IsAbstract
68- && x . IsAssignableToGenericType ( baseToolWindowType ) ) ;
69-
70- foreach ( Type ? toolWindowtype in toolWindowTypes )
71- {
72- MethodInfo initializeMethod = toolWindowtype . GetMethod (
73- "Initialize" ,
74- BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ;
75-
76- initializeMethod . Invoke ( null , new object [ ] { package } ) ;
77- }
78- }
7950 }
8051}
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Reflection ;
5+ using Microsoft . VisualStudio . Shell ;
6+
7+ namespace Community . VisualStudio . Toolkit
8+ {
9+ /// <summary>
10+ /// Extensions for an <see cref="ToolkitPackage"/>
11+ /// </summary>
12+ public static class ToolkitPackageExtensions
13+ {
14+ /// <summary>
15+ /// Automatically calls the <see cref="BaseToolWindow{T}.Initialize(ToolkitPackage)"/>
16+ /// method for every <see cref="BaseToolWindow{T}"/> in the package or provided assemblies.
17+ /// </summary>
18+ /// <param name="package">The package that contains the tool windows to register.</param>
19+ /// <param name="assemblies">The additional assemblies to look for tool windows in.</param>
20+ public static void RegisterToolWindows ( this ToolkitPackage package , params Assembly [ ] assemblies )
21+ {
22+ List < Assembly > assembliesList = assemblies . ToList ( ) ;
23+ Assembly packageAssembly = package . GetType ( ) . Assembly ;
24+ if ( ! assembliesList . Contains ( packageAssembly ) )
25+ assembliesList . Add ( packageAssembly ) ;
26+
27+ Type baseToolWindowType = typeof ( BaseToolWindow < > ) ;
28+ IEnumerable < Type > toolWindowTypes = assembliesList . SelectMany ( x => x . GetTypes ( ) )
29+ . Where ( x =>
30+ ! x . IsAbstract
31+ && x . IsAssignableToGenericType ( baseToolWindowType ) ) ;
32+
33+ foreach ( Type ? toolWindowtype in toolWindowTypes )
34+ {
35+ MethodInfo initializeMethod = toolWindowtype . GetMethod (
36+ "Initialize" ,
37+ BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ;
38+
39+ initializeMethod . Invoke ( null , new object [ ] { package } ) ;
40+ }
41+ }
42+ }
43+ }
Original file line number Diff line number Diff line change 4343 <Compile Include =" $(MSBuildThisFileDirectory)ExtensionMethods\IVsSolutionExtensions.cs" />
4444 <Compile Include =" $(MSBuildThisFileDirectory)ExtensionMethods\IVsTextViewExtensions.cs" />
4545 <Compile Include =" $(MSBuildThisFileDirectory)ExtensionMethods\TaskExtensions.cs" />
46+ <Compile Include =" $(MSBuildThisFileDirectory)ExtensionMethods\ToolkitPackageExtensions.cs" />
4647 <Compile Include =" $(MSBuildThisFileDirectory)ExtensionMethods\TypeExtensions.cs" />
4748 <Compile Include =" $(MSBuildThisFileDirectory)ExtensionMethods\WindowExtensions.cs" />
4849 <Compile Include =" $(MSBuildThisFileDirectory)Helpers\ContentTypes.cs" />
You can’t perform that action at this time.
0 commit comments