Share via


IVsDataHostService.TryGetService<T> Method

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

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

Syntax

'Declaration
Function TryGetService(Of T) As T
'Usage
Dim instance As IVsDataHostService 
Dim returnValue As T

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

Type Parameters

  • T

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 System;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Shell.Interop;

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

.NET Framework Security

See Also

Reference

IVsDataHostService Interface

IVsDataHostService Members

TryGetService Overload

Microsoft.VisualStudio.Data.Core Namespace