public AddService ( System.Guid serviceGuid, object instance ) : void | ||
serviceGuid | System.Guid | |
instance | object | |
Результат | void |
public static void Initialize() { // If we're in a real VS process, or if we already initialized, do nothing. if (Shell.ServiceProvider.GlobalProvider.GetService(typeof(SVsSettingsManager)) != null) return; // If the App() ctor didn't set a version, we're in the designer // The designer pre-loads our referenced assemblies, so we can't // use any other version. if (VsLoader.VsVersion == null) VsLoader.Load(new Version(11, 0, 0, 0)); var esm = ExternalSettingsManager.CreateForApplication(Path.Combine(VsLoader.InstallationDirectory, "devenv.exe")); var sp = new VsServiceProvider { UIShell = new ThemedVsUIShell(), serviceInstances = { // Used by Shell.ServiceProvider initialization { typeof(SVsActivityLog).GUID, new StubVsActivityLog() }, // Used by ColorThemeService { typeof(SVsSettingsManager).GUID, new SettingsManagerWrapper(esm) }, // Used by Shell.VsResourceKeys { new Guid("45652379-D0E3-4EA0-8B60-F2579AA29C93"), new SimpleVsWindowManager() }, // Used by KnownUIContexts { typeof(IVsMonitorSelection).GUID, new StubVsMonitorSelection() }, // Used by ShimCodeLensPresenterStyle { typeof(SUIHostLocale).GUID, new SystemUIHostLocale() }, { typeof(SVsFontAndColorCacheManager).GUID, new StubVsFontAndColorCacheManager() }, // Used by Roslyn's VisualStudioWaitIndicator { typeof(SVsThreadedWaitDialogFactory).GUID, new BaseWaitDialogFactory() }, // Used by Dev14's VsImageLoader, which is needed for Roslyn IntelliSense { typeof(SVsAppId).GUID, new SimpleVsAppId() }, // Used by DocumentPeekResult; service is SVsUIThreadInvokerPrivate { new Guid("72FD1033-2341-4249-8113-EF67745D84EA"), new AppDispatcherInvoker() }, // Used by KeyBindingHelper.GetKeyBinding, which is used by VSLightBulbPresenterStyle. { typeof(SDTE).GUID, new StubDTE() }, // Used by VsTaskSchedulerService; see below { typeof(SVsShell).GUID, new StubVsShell() }, } }; sp.AddService(typeof(SVsUIShell), sp.UIShell); Shell.ServiceProvider.CreateFromSetSite(sp); Instance = sp; // Add services that use IServiceProvider here sp.AddTaskSchedulerService(); // The designer loads Microsoft.VisualStudio.Shell.XX.0, // which we cannot reference directly (to avoid breaking // older versions). Therefore, I set the global property // for every available version using Reflection instead. foreach (var vsVersion in VsLoader.FindAllVersions().Where(v => v.Major >= 10)) { var type = Type.GetType("Microsoft.VisualStudio.Shell.ServiceProvider, Microsoft.VisualStudio.Shell." + vsVersion.ToString(2)); if (type == null) continue; type.GetMethod("CreateFromSetSite", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static) .Invoke(null, new[] { sp }); } }
public static void Initialize() { // If we're in a real VS process, or if we already initialized, do nothing. if (Shell.ServiceProvider.GlobalProvider.GetService(typeof(SVsSettingsManager)) != null) { return; } // If the App() ctor didn't set a version, we're in the designer // The designer pre-loads our referenced assemblies, so we can't // use any other version. if (VsLoader.VsVersion == null) { VsLoader.Load(new Version(11, 0, 0, 0)); } var esm = ExternalSettingsManager.CreateForApplication(Path.Combine(VsLoader.InstallationDirectory, "devenv.exe")); var sp = new VsServiceProvider { UIShell = new ThemedVsUIShell(), serviceInstances = { // Used by Shell.ServiceProvider initialization { typeof(SVsActivityLog).GUID, new StubVsActivityLog() }, // Used by ColorThemeService { typeof(SVsSettingsManager).GUID, new SettingsManagerWrapper(esm) }, // Used by Shell.VsResourceKeys { new Guid("45652379-D0E3-4EA0-8B60-F2579AA29C93"), new SimpleVsWindowManager() }, // Used by KnownUIContexts { typeof(IVsMonitorSelection).GUID, new StubVsMonitorSelection() }, // Used by ShimCodeLensPresenterStyle { typeof(SUIHostLocale).GUID, new SystemUIHostLocale() }, { typeof(SVsFontAndColorCacheManager).GUID, new StubVsFontAndColorCacheManager() }, // Used by Roslyn's VisualStudioWaitIndicator { typeof(SVsThreadedWaitDialogFactory).GUID, new BaseWaitDialogFactory() }, // Used by Dev14's VsImageLoader, which is needed for Roslyn IntelliSense { typeof(SVsAppId).GUID, new SimpleVsAppId() }, // Used by DocumentPeekResult; service is SVsUIThreadInvokerPrivate { new Guid("72FD1033-2341-4249-8113-EF67745D84EA"), new AppDispatcherInvoker() }, // Used by KeyBindingHelper.GetKeyBinding, which is used by VSLightBulbPresenterStyle. { typeof(SDTE).GUID, new StubDTE() }, // Used by VsTaskSchedulerService; see below { typeof(SVsShell).GUID, new StubVsShell() }, } }; sp.AddService(typeof(SVsUIShell), sp.UIShell); Shell.ServiceProvider.CreateFromSetSite(sp); Instance = sp; // Add services that use IServiceProvider here sp.AddTaskSchedulerService(); // The designer loads Microsoft.VisualStudio.Shell.XX.0, // which we cannot reference directly (to avoid breaking // older versions). Therefore, I set the global property // for every available version using Reflection instead. foreach (var vsVersion in VsLoader.FindAllVersions().Where(v => v.Major >= 10)) { var type = Type.GetType("Microsoft.VisualStudio.Shell.ServiceProvider, Microsoft.VisualStudio.Shell." + vsVersion.ToString(2)); if (type == null) { continue; } type.GetMethod("CreateFromSetSite", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static) .Invoke(null, new[] { sp }); } }