Class IDeviceRegistryExtensions
Extensions for IDeviceRegistry.
public static class IDeviceRegistryExtensions
- Inheritance
-
IDeviceRegistryExtensions
- Inherited Members
Methods
GetDeviceList<TDevice>(IDeviceRegistry)
Gets the list of registered devices of a particular device type.
public static IReadOnlyList<IRegisteredDevice<TDevice>> GetDeviceList<TDevice>(this IDeviceRegistry deviceRegistry) where TDevice : class
Parameters
deviceRegistry
IDeviceRegistryThe device registry.
Returns
- IReadOnlyList<IRegisteredDevice<TDevice>>
The list of devices.
Type Parameters
TDevice
The device type.
Remarks
Any configuration changes while the application is running that cause the device list for type TDevice
to be regenerated will cause all active devices
of that type to be disposed (if they implement IDisposable and recreated from the new configuration. While configuration changes typically only happen during application startup,
clients should nonetheless hold on to and use the returned references for only as long as is needed.
Exceptions
- ArgumentNullException
deviceRegistry
is null.
GetDeviceService<TService>(IDeviceRegistry, Type)
Attempts to get a service registered for a device type.
public static TService GetDeviceService<TService>(this IDeviceRegistry deviceRegistry, Type deviceType)
Parameters
deviceRegistry
IDeviceRegistryThe device registry.
deviceType
TypeThe device type.
Returns
- TService
The first service of type
TService
in the list of services specified for the registered device typedeviceType
, or the default value forTService
if the device typedeviceType
is not registered, or there is no service of typeTService
specified for the device type.
Type Parameters
TService
The service type.
Exceptions
- ArgumentNullException
deviceRegistry
is null.- ArgumentNullException
deviceType
is null.
GetDevice<TDevice>(IDeviceRegistry, string)
Gets a registered device of a particular device type.
public static TDevice GetDevice<TDevice>(this IDeviceRegistry deviceRegistry, string name = null) where TDevice : class
Parameters
deviceRegistry
IDeviceRegistryThe device registry.
name
stringAn optional device name.
Returns
- TDevice
The device, or null if not found. See the remarks for more details.
Type Parameters
TDevice
The device type.
Remarks
- If device type
TDevice
has never been registered or currently has no configured devices, null will be returned. - Otherwise, if
name
is null or empty, then the first registered device of typeTDevice
will be returned. - Otherwise, the first registered device of type
TDevice
with a name that matchesname
(case-sensitive) will be returned, or null if a match is not found.
Any configuration changes while the application is running that cause the device list for type TDevice
to be regenerated will cause all active devices
of that type to be disposed (if they implement IDisposable and recreated from the new configuration. While configuration changes typically only happen during application startup,
clients should nonetheless hold on to and use the returned reference for only as long as is needed.
Exceptions
- ArgumentNullException
deviceRegistry
is null.