Partager via


IVsDataHostService.GetService<T> Method (Guid)

Gets 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

'Déclaration
Function GetService(Of T) ( _
    serviceGuid As Guid _
) As T
T GetService<T>(
    Guid serviceGuid
)
generic<typename T>
T GetService(
    Guid serviceGuid
)
abstract GetService : 
        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.

Exceptions

Exception Condition
ServiceNotFoundException

The service was not found.

Remarks

This method should be called for services that are assumed to be always 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 DdexHostSvcExample5
{
    private static readonly Guid SID_IVsUIShell =
        new Guid("B61FC35B-EEBF-4dec-BFF1-28A2DD43C38F");

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

.NET Framework Security

See Also

Reference

IVsDataHostService Interface

GetService Overload

Microsoft.VisualStudio.Data.Core Namespace