IVsDataHostService.TryGetService<T> Generic Method (Guid)

Tries to get a global Visual Studio service that is registered with the specified class ID 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 T) ( _
    serviceGuid As Guid _
) As T
'使用
Dim instance As IVsDataHostService
Dim serviceGuid As Guid
Dim returnValue As T

returnValue = instance.TryGetService(serviceGuid)
T TryGetService<T>(
    Guid serviceGuid
)
generic<typename T>
T TryGetService(
    Guid serviceGuid
)
JScript does not support generic types or methods.

Type Parameters

  • T

Parameters

  • serviceGuid
    Type: System.Guid

    The class ID of the service to retrieve.

Return Value

Type: T

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 service ID and interface type.

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

public class DdexHostSvcExample9
{
    private static readonly Guid SID_IVsUIShell =
        new Guid("B61FC35B-EEBF-4dec-BFF1-28A2DD43C38F");

    public static IVsUIShell GetIVsUIShell(IVsDataHostService hostService)
    {
        return hostService.TryGetService<IVsUIShell>(SID_IVsUIShell);
    }
}

Permissions

See Also

Reference

IVsDataHostService Interface

IVsDataHostService Members

TryGetService Overload

Microsoft.VisualStudio.Data.Core Namespace