Class BaseBindableObject
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
loggerILoggerOptional 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
Properties
Logger
The logger instance for this object.
protected ILogger Logger { get; }
Property Value
Methods
ClearValue(string?)
Clears the value of the specified property and raises the PropertyChanged event.
protected bool ClearValue(string? propertyName = null)
Parameters
propertyNamestringThe 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
defaultValueTThe default value to return if the property is not set.
propertyNamestringThe 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
TThe 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
defaultValueTThe default value to use if the property is not set.
propertyNamestringThe 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
TThe 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
propertyNamestringThe 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
propertyNamestringThe 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
valueTThe value to set.
propertyNamestringThe 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
TThe 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
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
propertyNamestringThe name of the property to monitor.
unwantedValueTThe value to avoid.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
TThe 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
propertyNamestringThe name of the property to monitor.
expectedValueTThe value to wait for.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
TThe 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
propertyNamestringThe name of the property to monitor.
conditionFunc<T, bool>A function that determines whether the property value satisfies the condition.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
TThe 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
propertyNamestringThe name of the property to monitor.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
TThe 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
propertyNamestringThe name of the property to monitor.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
TThe 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