ServiceProvider.GetService Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the service object of the specified type.
Overloads
GetService<T>(IServiceProvider) |
Retrieves the service object of the specified type. |
GetService<T>(IServiceProvider, Boolean) |
Retrieves the service object of the specified type, and throws an exception if the service is not found. |
GetService<T>(IServiceProvider)
Retrieves the service object of the specified type.
public:
generic <typename T>
static T GetService(IServiceProvider ^ serviceProvider);
public static T GetService<T> (IServiceProvider serviceProvider);
static member GetService : IServiceProvider -> 'T
Public Shared Function GetService(Of T) (serviceProvider As IServiceProvider) As T
Type Parameters
- T
The type of the service provider.
Parameters
- serviceProvider
- IServiceProvider
An object that specifies the type of service object to get.
Returns
A type of service object.
Applies to
GetService<T>(IServiceProvider, Boolean)
Retrieves the service object of the specified type, and throws an exception if the service is not found.
public:
generic <typename T>
static T GetService(IServiceProvider ^ serviceProvider, bool throwIfNotFound);
public static T GetService<T> (IServiceProvider serviceProvider, bool throwIfNotFound);
static member GetService : IServiceProvider * bool -> 'T
Public Shared Function GetService(Of T) (serviceProvider As IServiceProvider, throwIfNotFound As Boolean) As T
Type Parameters
- T
The type of the object service to get.
Parameters
- serviceProvider
- IServiceProvider
An object that specifies the type of service object to get.
- throwIfNotFound
- Boolean
true
if service is not found; otherwise, false
.
Returns
The service object of the specified type, and throws an exception if the service is not found.