Class DeviceRegistryExtensions
Extension members for IDeviceRegistry.
public static class DeviceRegistryExtensions
- Inheritance
-
DeviceRegistryExtensions
- 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
deviceRegistryIDeviceRegistry
Returns
- IReadOnlyList<IRegisteredDevice<TDevice>>
The list of devices.
Type Parameters
TDeviceThe 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.
GetDeviceService<TService>(IDeviceRegistry, Type)
Attempts to get a service registered for a device type.
public static TService? GetDeviceService<TService>(this IDeviceRegistry deviceRegistry, Type deviceType) where TService : notnull
Parameters
deviceRegistryIDeviceRegistrydeviceTypeTypeThe device type.
Returns
- TService
The first service of type
TServicein the list of services specified for the registered device typedeviceType, or the default value forTServiceif the device typedeviceTypeis not registered, or there is no service of typeTServicespecified for the device type.
Type Parameters
TServiceThe service type.
Exceptions
- ArgumentNullException
deviceTypeis 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
deviceRegistryIDeviceRegistrynamestringAn optional device name.
Returns
- TDevice
The device, or null if not found. See the remarks for more details.
Type Parameters
TDeviceThe device type.
Remarks
- If device type
TDevicehas never been registered or currently has no configured devices, null will be returned. - Otherwise, if
nameis null or empty, then the first registered device of typeTDevicewill be returned. - Otherwise, the first registered device of type
TDevicewith 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.