Table of Contents

Class CharacteristicAccessorExtensions

Namespace
Bluetooth.Core.Scanning.Profiles
Assembly
Bluetooth.Core.Scanning.dll

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

accessor IBluetoothCharacteristicAccessor<TRead, TWrite>

The accessor describing the target characteristic.

device IBluetoothRemoteDevice

The connected remote device.

defaultValue TRead

The value returned when reading is unavailable.

skipIfPreviouslyRead bool

When true, skips the native read if a previous value is already cached.

timeout TimeSpan?

Optional timeout for exploration and read operations.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

ValueTask<TRead>

The decoded typed value when readable; otherwise defaultValue.

Type Parameters

TRead

The typed value produced when reading the characteristic.

TWrite

The typed value accepted when writing the characteristic.

Exceptions

ArgumentNullException

Thrown when accessor or device is 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

accessor IBluetoothCharacteristicAccessor<TRead, TWrite>

The accessor describing the target characteristic.

device IBluetoothRemoteDevice

The connected remote device.

defaultValue TRead

The value returned when reading is unavailable.

skipIfPreviouslyRead bool

When true, skips the native read if a previous value is already cached.

timeout TimeSpan?

Optional timeout for exploration and read operations.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

ValueTask<TRead>

The decoded typed value when readable; otherwise defaultValue.

Type Parameters

TRead

The typed value produced when reading the characteristic.

TWrite

The 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

accessor IBluetoothCharacteristicAccessor<TRead, TWrite>

The accessor describing the target characteristic.

device IBluetoothRemoteDevice

The connected remote device.

value TWrite

The typed value to encode and write.

skipIfOldValueMatchesNewValue bool

When true, skips native write if current and new values match.

timeout TimeSpan?

Optional timeout for exploration and write operations.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

ValueTask<bool>

true when the value was written; otherwise false.

Type Parameters

TRead

The typed value produced when reading the characteristic.

TWrite

The typed value accepted when writing the characteristic.

Exceptions

ArgumentNullException

Thrown when accessor or device is 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

accessor IBluetoothCharacteristicAccessor<TRead, TWrite>

The accessor describing the target characteristic.

device IBluetoothRemoteDevice

The connected remote device.

value TWrite

The typed value to encode and write.

skipIfOldValueMatchesNewValue bool

When true, skips native write if current and new values match.

timeout TimeSpan?

Optional timeout for exploration and write operations.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

ValueTask<bool>

true when the value was written; otherwise false.

Type Parameters

TRead

The typed value produced when reading the characteristic.

TWrite

The typed value accepted when writing the characteristic.