Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add IsNull to bindable property #47

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/BB84.Notifications/BindableProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public sealed class BindableProperty<T> : IBindableProperty<T>
public BindableProperty(T value)
=> _value = value;

/// <inheritdoc/>
public bool IsNull => _value is null;

/// <inheritdoc/>
public T Value
{
Expand Down
5 changes: 5 additions & 0 deletions src/BB84.Notifications/Interfaces/IBindableProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace BB84.Notifications.Interfaces;
/// <typeparam name="T">The value type to work with.</typeparam>
public interface IBindableProperty<T> : INotifyPropertyChanged, INotifyPropertyChanging
{
/// <summary>
/// Is the value of the bindable property null?
/// </summary>
bool IsNull { get; }

/// <summary>
/// The actual value of the bindable property.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions tests/BB84.NotificationsTests/BindablePropertyTests.IsNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using BB84.Notifications;
using BB84.Notifications.Interfaces;

namespace BB84.NotificationsTests;

public sealed partial class BindablePropertyTests
{
[DataTestMethod]
[DataRow(456, false)]
[DataRow(6.3d, false)]
[DataRow(0.75f, false)]
[DataRow(45623415L, false)]
[DataRow(0xFE, false)]
[DataRow(true, false)]
[DataRow("Test", false)]
[DataRow(null, true)]
public void IsNull(object? value, bool expected)
{
IBindableProperty<object?> bindableProperty = new BindableProperty<object?>(value);

Assert.AreEqual(expected, bindableProperty.IsNull);
}
}