QuickOPC User's Guide and Reference
TryGetRequiredService<TService> Method



OpcLabs.BaseLib Assembly > OpcLabs.BaseLib.Extensions Namespace > IServiceProviderExtension Class : TryGetRequiredService<TService> Method
The type of service object to get.
The service provider.
A service object of type TService.
Tries to gets the required service object of the specified type, casting it to the same type.
Syntax
'Declaration
 
<ExtensionAttribute()>
<CanBeNullAttribute()>
Public Shared Function TryGetRequiredService(Of TService)( _
   ByVal serviceProvider As IServiceProvider, _
   ByRef service As TService _
) As Exception
'Usage
 
Dim serviceProvider As IServiceProvider
Dim service As TService
Dim value As Exception
 
value = IServiceProviderExtension.TryGetRequiredService(Of TService)(serviceProvider, service)
[Extension()]
[CanBeNull()]
public static Exception TryGetRequiredService<TService>( 
   IServiceProvider serviceProvider,
   out TService service
)
[Extension()]
[CanBeNull()]
public:
static Exception^ TryGetRequiredServicegeneric<typename TService>
( 
   IServiceProvider^ serviceProvider,
   [Out] TService^ service
) 

Parameters

serviceProvider
The service provider.
service
A service object of type TService.

Type Parameters

TService
The type of service object to get.

Return Value

Returns null when the service object has been successfully retrieved. If there is no service of the requested type, returns a non-null exception.
Requirements

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

See Also

Reference

IServiceProviderExtension Class
IServiceProviderExtension Members