IVsDataHostService.TryGetService<TService, TInterface> Generic Method

Tries to get a global Visual Studio service of the specified type that implements the specified interface.

Namespace:  Microsoft.VisualStudio.Data.Core
Assembly:  Microsoft.VisualStudio.Data.Core (in Microsoft.VisualStudio.Data.Core.dll)

Syntax

'宣言
Function TryGetService(Of TService, TInterface) As TInterface
'使用
Dim instance As IVsDataHostService
Dim returnValue As TInterface

returnValue = instance.TryGetService()
TInterface TryGetService<TService, TInterface>()
generic<typename TService, typename TInterface>
TInterface TryGetService()
JScript does not support generic types or methods.

Type Parameters

  • TService

  • TInterface

Return Value

Type: TInterface

The service instance, if found; otherwise, a null reference (Nothing in Visual Basic).

Remarks

This method should be called for services that are optional or not known to always be present.

Examples

The following code demonstrates calling this method to retrieve a standard Visual Studio global service, using a separate service type and interface type.

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>();
    }
}

Permissions

See Also

Reference

IVsDataHostService Interface

IVsDataHostService Members

TryGetService Overload

Microsoft.VisualStudio.Data.Core Namespace