Table of Contents

Class BaseBindableObject

Namespace
Bluetooth.Core
Assembly
Bluetooth.Core.dll

Provides a base class for bindable objects with property change notification, value storage.

public abstract class BaseBindableObject : INotifyPropertyChanged
Inheritance
BaseBindableObject
Implements
Derived
Inherited Members

Constructors

BaseBindableObject(ILogger?)

Initializes a new instance of the BaseBindableObject class.

protected BaseBindableObject(ILogger? logger = null)

Parameters

logger ILogger

Optional logger instance for tracking property changes.

Fields

_logger

The logger instance used by LoggerMessage source-generated methods in derived classes.

[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Required by LoggerMessage source generator which resolves _logger through the class hierarchy.")]
protected ILogger _logger

Field Value

ILogger

Properties

Logger

The logger instance for this object.

protected ILogger Logger { get; }

Property Value

ILogger

Methods

ClearValue(string?)

Clears the value of the specified property and raises the PropertyChanged event.

protected bool ClearValue(string? propertyName = null)

Parameters

propertyName string

The name of the property to clear. If not provided, the caller's member name is used.

Returns

bool

True if the property was cleared; otherwise, false.

Exceptions

ArgumentException

If the property name is null or whitespace.

GetValueOrDefault<T>(T, string?)

Gets the value of the specified property without storing a default value if not present.

protected T GetValueOrDefault<T>(T defaultValue, string? propertyName = null)

Parameters

defaultValue T

The default value to return if the property is not set.

propertyName string

The name of the property. If not provided, the caller's member name is used.

Returns

T

The value of the property, or the default value if not set.

Type Parameters

T

The type of the property value.

Exceptions

ArgumentException

If the property name is null or whitespace.

GetValue<T>(T, string?)

Gets the value of the specified property, or sets and returns the default value if not present.

protected T GetValue<T>(T defaultValue, string? propertyName = null)

Parameters

defaultValue T

The default value to use if the property is not set.

propertyName string

The name of the property. If not provided, the caller's member name is used.

Returns

T

The value of the property, or the default value if not set.

Type Parameters

T

The type of the property value.

Exceptions

ArgumentException

If the property name is null or whitespace.

HasValue(string?)

Determines whether a value has been set for the specified property.

protected bool HasValue(string? propertyName = null)

Parameters

propertyName string

The name of the property. If not provided, the caller's member name is used.

Returns

bool

True if a value has been set for the property; otherwise, false.

Exceptions

ArgumentException

If the property name is null or whitespace.

OnPropertyChanged(string?)

Raises the PropertyChanged event for the specified property.

protected virtual void OnPropertyChanged(string? propertyName = null)

Parameters

propertyName string

The name of the property that changed. If not provided, the caller's member name is used.

SetValue<T>(T, string?)

Sets the value of the specified property and raises the PropertyChanged event if the value changes.

protected bool SetValue<T>(T value, string? propertyName = null)

Parameters

value T

The value to set.

propertyName string

The name of the property. If not provided, the caller's member name is used.

Returns

bool

True if the value was changed and the property was set; otherwise, false.

Type Parameters

T

The type of the property value.

Exceptions

ArgumentException

If the property name is null or whitespace.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

WaitForPropertyToBeDifferentThanValue<T>(string, T, TimeSpan?, CancellationToken)

Waits asynchronously until the specified property does not equal the unwanted value, or until the timeout expires.

protected ValueTask<T> WaitForPropertyToBeDifferentThanValue<T>(string propertyName, T unwantedValue, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

propertyName string

The name of the property to monitor.

unwantedValue T

The value to avoid.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<T>

A task that completes when the property does not equal the unwanted value or the timeout expires.

Type Parameters

T

The type of the property value.

WaitForPropertyToBeOfValue<T>(string, T, TimeSpan?, CancellationToken)

Waits asynchronously until the specified property equals the expected value, or until the timeout expires.

protected ValueTask<T> WaitForPropertyToBeOfValue<T>(string propertyName, T expectedValue, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

propertyName string

The name of the property to monitor.

expectedValue T

The value to wait for.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<T>

A task that completes when the property equals the expected value or the timeout expires.

Type Parameters

T

The type of the property value.

WaitForPropertyToBe<T>(string, Func<T?, bool>, TimeSpan?, CancellationToken)

Waits asynchronously until the specified property satisfies the given condition, or until the timeout expires.

protected ValueTask<T> WaitForPropertyToBe<T>(string propertyName, Func<T?, bool> condition, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

propertyName string

The name of the property to monitor.

condition Func<T, bool>

A function that determines whether the property value satisfies the condition.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<T>

A task that completes when the property satisfies the condition or the timeout expires.

Type Parameters

T

The type of the property value.

Exceptions

ArgumentException

If the property name is null or whitespace.

WaitForPropertyToChangeNotNull<T>(string, TimeSpan?, CancellationToken)

Waits asynchronously until the property value changes to a new value, or until the timeout expires.

protected ValueTask<T> WaitForPropertyToChangeNotNull<T>(string propertyName, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

propertyName string

The name of the property to monitor.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<T>

A task that completes when the property satisfies the condition or the timeout expires.

Type Parameters

T

The type of the property value.

Exceptions

ArgumentException

If the property name is null or whitespace.

WaitForPropertyToChange<T>(string, TimeSpan?, CancellationToken)

Waits asynchronously until the property value changes, or until the timeout expires.

protected ValueTask<T?> WaitForPropertyToChange<T>(string propertyName, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

propertyName string

The name of the property to monitor.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<T>

A task that completes when the property satisfies the condition or the timeout expires.

Type Parameters

T

The type of the property value.

Exceptions

ArgumentException

If the property name is null or whitespace.

Events

PropertyChanged

Occurs when a property value changes.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler