Class CharacteristicAccessorExtensions
Convenience helpers for resilient characteristic accessor operations.
public static class CharacteristicAccessorExtensions
- Inheritance
-
CharacteristicAccessorExtensions
- Inherited Members
Methods
ReadOrDefaultAsync<TRead, TWrite>(IBluetoothCharacteristicAccessor<TRead, TWrite>, IBluetoothRemoteDevice, TRead, bool, TimeSpan?, CancellationToken)
Reads a typed value and returns defaultValue when the target service/characteristic
cannot be resolved or does not support reading.
public static ValueTask<TRead> ReadOrDefaultAsync<TRead, TWrite>(this IBluetoothCharacteristicAccessor<TRead, TWrite> accessor, IBluetoothRemoteDevice device, TRead defaultValue = default, bool skipIfPreviouslyRead = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
accessorIBluetoothCharacteristicAccessor<TRead, TWrite>The accessor describing the target characteristic.
deviceIBluetoothRemoteDeviceThe connected remote device.
defaultValueTReadThe value returned when reading is unavailable.
skipIfPreviouslyReadboolWhen true, skips the native read if a previous value is already cached.
timeoutTimeSpan?Optional timeout for exploration and read operations.
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
- ValueTask<TRead>
The decoded typed value when readable; otherwise
defaultValue.
Type Parameters
TReadThe typed value produced when reading the characteristic.
TWriteThe typed value accepted when writing the characteristic.
Exceptions
- ArgumentNullException
Thrown when
accessorordeviceis null.- CharacteristicAccessorException
Propagates non-resolution accessor/codec failures (for example decode failures) to avoid masking data issues.
ReadValueOrDefaultAsync<TRead, TWrite>(IBluetoothCharacteristicAccessor<TRead, TWrite>, IBluetoothRemoteDevice, TRead, bool, TimeSpan?, CancellationToken)
Reads a typed value and returns defaultValue when the target service/characteristic
cannot be resolved or does not support reading.
public static ValueTask<TRead> ReadValueOrDefaultAsync<TRead, TWrite>(this IBluetoothCharacteristicAccessor<TRead, TWrite> accessor, IBluetoothRemoteDevice device, TRead defaultValue = default, bool skipIfPreviouslyRead = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
accessorIBluetoothCharacteristicAccessor<TRead, TWrite>The accessor describing the target characteristic.
deviceIBluetoothRemoteDeviceThe connected remote device.
defaultValueTReadThe value returned when reading is unavailable.
skipIfPreviouslyReadboolWhen true, skips the native read if a previous value is already cached.
timeoutTimeSpan?Optional timeout for exploration and read operations.
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
- ValueTask<TRead>
The decoded typed value when readable; otherwise
defaultValue.
Type Parameters
TReadThe typed value produced when reading the characteristic.
TWriteThe typed value accepted when writing the characteristic.
TryWriteAsync<TRead, TWrite>(IBluetoothCharacteristicAccessor<TRead, TWrite>, IBluetoothRemoteDevice, TWrite, bool, TimeSpan?, CancellationToken)
Attempts to write a typed value and returns false when the target service/characteristic
cannot be resolved or does not support writing.
public static ValueTask<bool> TryWriteAsync<TRead, TWrite>(this IBluetoothCharacteristicAccessor<TRead, TWrite> accessor, IBluetoothRemoteDevice device, TWrite value, bool skipIfOldValueMatchesNewValue = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
accessorIBluetoothCharacteristicAccessor<TRead, TWrite>The accessor describing the target characteristic.
deviceIBluetoothRemoteDeviceThe connected remote device.
valueTWriteThe typed value to encode and write.
skipIfOldValueMatchesNewValueboolWhen true, skips native write if current and new values match.
timeoutTimeSpan?Optional timeout for exploration and write operations.
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
Type Parameters
TReadThe typed value produced when reading the characteristic.
TWriteThe typed value accepted when writing the characteristic.
Exceptions
- ArgumentNullException
Thrown when
accessorordeviceis null.- CharacteristicAccessorException
Propagates non-resolution accessor/codec failures (for example encode failures) to avoid masking data issues.
TryWriteValueAsync<TRead, TWrite>(IBluetoothCharacteristicAccessor<TRead, TWrite>, IBluetoothRemoteDevice, TWrite, bool, TimeSpan?, CancellationToken)
Attempts to write a typed value and returns false when the target service/characteristic
cannot be resolved or does not support writing.
public static ValueTask<bool> TryWriteValueAsync<TRead, TWrite>(this IBluetoothCharacteristicAccessor<TRead, TWrite> accessor, IBluetoothRemoteDevice device, TWrite value, bool skipIfOldValueMatchesNewValue = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
accessorIBluetoothCharacteristicAccessor<TRead, TWrite>The accessor describing the target characteristic.
deviceIBluetoothRemoteDeviceThe connected remote device.
valueTWriteThe typed value to encode and write.
skipIfOldValueMatchesNewValueboolWhen true, skips native write if current and new values match.
timeoutTimeSpan?Optional timeout for exploration and write operations.
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
Type Parameters
TReadThe typed value produced when reading the characteristic.
TWriteThe typed value accepted when writing the characteristic.