获取实现了指定接口指定类型的全局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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。