QuickOPC User's Guide and Reference
GetService<TService> Method (IServiceProviderExtension)



OpcLabs.BaseLib Assembly > OpcLabs.BaseLib.Extensions Namespace > IServiceProviderExtension Class : GetService<TService> Method
The type of service object to get.
The service provider.
Gets the service object of the specified type, casting it to the same type.
Syntax
'Declaration
 
<ExtensionAttribute()>
<CanBeNullAttribute()>
Public Shared Function GetService(Of TService As Class)( _
   ByVal serviceProvider As IServiceProvider _
) As TService
'Usage
 
Dim serviceProvider As IServiceProvider
Dim value As TService
 
value = IServiceProviderExtension.GetService(Of TService)(serviceProvider)
[Extension()]
[CanBeNull()]
public static TService GetService<TService>( 
   IServiceProvider serviceProvider
)
where TService: class
[Extension()]
[CanBeNull()]
public:
static TService^ GetServicegeneric<typename TService>
( 
   IServiceProvider^ serviceProvider
) 
where TService: ref class

Parameters

serviceProvider
The service provider.

Type Parameters

TService
The type of service object to get.

Return Value

A service object of type TService.
Remarks

This is functionally based on the System.IServiceProvider.GetService(System.Type), but provides a strongly typed result, while removing the need to specify the type using the typeof keyword at the same time.

Requirements

Target Platforms: .NET Framework: Windows 7 with SP1, Windows Server 2012; .NET Core: Linux, Microsoft Windows

See Also

Reference

IServiceProviderExtension Class
IServiceProviderExtension Members