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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。