IVsDataHostService.TryGetService<TService, TInterface> 方法

尝试获取实现了指定接口指定类型的全局Visual Studio服务。

命名空间:  Microsoft.VisualStudio.Data.Core
程序集:  Microsoft.VisualStudio.Data.Core(在 Microsoft.VisualStudio.Data.Core.dll 中)

语法

声明
Function TryGetService(Of TService, TInterface) As TInterface
TInterface TryGetService<TService, TInterface>()
generic<typename TService, typename TInterface>
TInterface TryGetService()
abstract TryGetService : unit -> 'TInterface 
JScript 不支持泛型类型或方法。

类型参数

  • TService
    服务。
  • TInterface
    类型。

返回值

类型:TInterface
服务实例,因此,如果找到;否则,nullnull 引用(在 Visual Basic 中为 Nothing)。

备注

对于是可选的服务调用或不了解此方法始终存在。

示例

使用单独的服务类型和接口类型,下面的代码演示调用此方法检索一项标准Visual Studio全局服务。

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

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

.NET Framework 安全性

请参见

参考

IVsDataHostService 接口

TryGetService 重载

Microsoft.VisualStudio.Data.Core 命名空间