diff --git a/src/VisualStudio/Core/Def/Implementation/Experimentation/KeybindingResetDetector.cs b/src/VisualStudio/Core/Def/Implementation/Experimentation/KeybindingResetDetector.cs index 1762f240674dd..3f4eb03778a05 100644 --- a/src/VisualStudio/Core/Def/Implementation/Experimentation/KeybindingResetDetector.cs +++ b/src/VisualStudio/Core/Def/Implementation/Experimentation/KeybindingResetDetector.cs @@ -114,7 +114,7 @@ private void InitializeCore() return; } - var vsShell = _serviceProvider.GetService(); + var vsShell = _serviceProvider.GetService(); var hr = vsShell.IsPackageInstalled(ReSharperPackageGuid, out var extensionEnabled); if (ErrorHandler.Failed(hr)) { @@ -127,7 +127,7 @@ private void InitializeCore() if (_resharperExtensionInstalledAndEnabled) { // We need to monitor for suspend/resume commands, so create and install the command target and the modal callback. - var priorityCommandTargetRegistrar = _serviceProvider.GetService(); + var priorityCommandTargetRegistrar = _serviceProvider.GetService(); hr = priorityCommandTargetRegistrar.RegisterPriorityCommandTarget( dwReserved: 0 /* from docs must be 0 */, pCmdTrgt: this, @@ -335,7 +335,7 @@ async Task EnsureOleCommandTargetAsync() await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - _oleCommandTarget = _serviceProvider.GetService(); + _oleCommandTarget = _serviceProvider.GetService(); } } @@ -345,7 +345,7 @@ private void RestoreVsKeybindings() if (_uiShell == null) { - _uiShell = _serviceProvider.GetService(); + _uiShell = _serviceProvider.GetService(); } ErrorHandler.ThrowOnFailure(_uiShell.PostExecCommand( @@ -432,7 +432,7 @@ private async Task ShutdownAsync() if (_priorityCommandTargetCookie != VSConstants.VSCOOKIE_NIL) { - var priorityCommandTargetRegistrar = _serviceProvider.GetService(); + var priorityCommandTargetRegistrar = _serviceProvider.GetService(); var cookie = _priorityCommandTargetCookie; _priorityCommandTargetCookie = VSConstants.VSCOOKIE_NIL; var hr = priorityCommandTargetRegistrar.UnregisterPriorityCommandTarget(cookie); diff --git a/src/VisualStudio/Core/Def/Implementation/Extensions/ServiceProviderExtensions.cs b/src/VisualStudio/Core/Def/Implementation/Extensions/ServiceProviderExtensions.cs deleted file mode 100644 index 5343351694281..0000000000000 --- a/src/VisualStudio/Core/Def/Implementation/Extensions/ServiceProviderExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics; - -namespace Microsoft.VisualStudio.LanguageServices.Implementation.Extensions -{ - internal static class ServiceProviderExtensions - { - public static TInterface GetService(this IServiceProvider serviceProvider) - { - var service = (TInterface)serviceProvider.GetService(typeof(TService)); - Debug.Assert(service != null); - return service; - } - } -} diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ClassView/AbstractSyncClassViewCommandHandler.cs b/src/VisualStudio/Core/Def/Implementation/Library/ClassView/AbstractSyncClassViewCommandHandler.cs index 214a2b35bf71a..a1e0ad01b23b9 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ClassView/AbstractSyncClassViewCommandHandler.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ClassView/AbstractSyncClassViewCommandHandler.cs @@ -9,7 +9,7 @@ using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.Commanding; -using Microsoft.VisualStudio.LanguageServices.Implementation.Extensions; +using Microsoft.VisualStudio.LanguageServices.Utilities; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs index 2687b3b81cf07..c8782d0474334 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs @@ -1033,7 +1033,7 @@ private bool TryGetFrame(CodeAnalysis.TextDocument document, [NotNullWhen(return // document using its ItemId. Thus, we must use OpenDocumentViaProject, which only // depends on the file path. - var openDocumentService = ServiceProvider.GlobalProvider.GetService(); + var openDocumentService = ServiceProvider.GlobalProvider.GetService(); return ErrorHandler.Succeeded(openDocumentService.OpenDocumentViaProject( document.FilePath, VSConstants.LOGVIEWID.TextView_guid, @@ -1072,7 +1072,7 @@ public void CloseDocumentCore(DocumentId documentId) var filePath = this.GetFilePath(documentId); if (filePath != null) { - var openDocumentService = ServiceProvider.GlobalProvider.GetService(); + var openDocumentService = ServiceProvider.GlobalProvider.GetService(); if (ErrorHandler.Succeeded(openDocumentService.IsDocumentOpen(null, 0, filePath, Guid.Empty, 0, out var uiHierarchy, null, out var frame, out var isOpen))) { // TODO: do we need save argument for CloseDocument? diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index a1e3a045c5adf..2f1e4fe9db179 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -24,9 +24,9 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.Editor; -using Microsoft.VisualStudio.LanguageServices.Implementation.Extensions; using Microsoft.VisualStudio.LanguageServices.Implementation.Library; using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; +using Microsoft.VisualStudio.LanguageServices.Utilities; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Text; diff --git a/src/VisualStudio/Core/Def/Utilities/IServiceProviderExtensions.cs b/src/VisualStudio/Core/Def/Utilities/IServiceProviderExtensions.cs index 578a160088f1f..a15e14b4d8407 100644 --- a/src/VisualStudio/Core/Def/Utilities/IServiceProviderExtensions.cs +++ b/src/VisualStudio/Core/Def/Utilities/IServiceProviderExtensions.cs @@ -3,19 +3,18 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; namespace Microsoft.VisualStudio.LanguageServices.Utilities { internal static class IServiceProviderExtensions { - /// - /// Returns the specified interface from the service. This is useful when the service and interface differ - /// - public static TInterfaceType GetService(this IServiceProvider sp) - where TInterfaceType : class - where TServiceType : class + /// + public static TInterface GetService(this IServiceProvider sp) { - return (TInterfaceType)sp.GetService(typeof(TServiceType)); + var service = (TInterface)sp.GetService(typeof(TService)); + Debug.Assert(service != null); + return service; } ///