共用方式為


IVsDataHostService.GetService<TService, TInterface> 方法

取得實作指定的介面指定型別的全域 Visual Studio 服務。

命名空間:  Microsoft.VisualStudio.Data.Core
組件:  Microsoft.VisualStudio.Data.Core (在 Microsoft.VisualStudio.Data.Core.dll 中)

語法

'宣告
Function GetService(Of TService, TInterface) As TInterface
TInterface GetService<TService, TInterface>()
generic<typename TService, typename TInterface>
TInterface GetService()
abstract GetService : unit -> 'TInterface 
JScript 不支援泛型型別或方法。

型別參數

  • TService
    服務。
  • TInterface
    介面。

傳回值

型別:TInterface
服務的執行個體。

例外狀況

例外狀況 條件
ServiceNotFoundException

找不到服務。

備註

應該假設一定存在的服務呼叫這個方法。

範例

使用不同的服務型別和介面型別,下列程式碼會示範如何呼叫這個方法會擷取一個標準 Visual Studio 全域服務。

using System;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Shell.Interop;

public class DdexHostSvcExample6
{
    public static IVsUIShell GetIVsUIShell(IVsDataHostService hostService)
    {
        return hostService.GetService<SVsUIShell, IVsUIShell>();
    }
}

.NET Framework 安全性

請參閱

參考

IVsDataHostService 介面

GetService 多載

Microsoft.VisualStudio.Data.Core 命名空間