Compartir a través de


IVsDataHostService.TryGetService<T> 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

'Declaration
Function TryGetService(Of T) ( _
    serviceGuid As Guid _
) As T
T TryGetService<T>(
    Guid serviceGuid
)
generic<typename T>
T TryGetService(
    Guid serviceGuid
)
abstract TryGetService : 
        serviceGuid:Guid -> 'T 
JScript does not support generic types or methods.

Type Parameters

  • T
    The interface.

Parameters

  • serviceGuid
    Type: System.Guid

    The class ID of the service to retrieve.

Return Value

Type: T
The service instance, if found; otherwise, nulla 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);
    }
}

.NET Framework Security

See Also

Reference

IVsDataHostService Interface

TryGetService Overload

Microsoft.VisualStudio.Data.Core Namespace