Skip to content

Commit face717

Browse files
committed
refac: interface and class naming
changes: - renamed all the interfaces - renamed all the implementations - renamed all the unit tests - improved comments - added new constructors closes #76
1 parent 68ec395 commit face717

26 files changed

+118
-117
lines changed

src/BB84.Notifications/BindableProperty.cs

-46
This file was deleted.

src/BB84.Notifications/Components/PropertyChangedEventArgs.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
namespace BB84.Notifications.Components;
44

55
/// <summary>
6-
/// The property changed event args class.
6+
/// Provides data for the <see cref="INotifyPropertyChanged"/> event.
77
/// </summary>
88
/// <typeparam name="T">The type to work with.</typeparam>
9-
/// <remarks>
10-
/// Initializes a instance of the property changed event args class.
11-
/// </remarks>
12-
/// <param name="name">The name of the property that is changed.</param>
9+
/// <param name="propertyName">The name of the property that is changed.</param>
1310
/// <param name="value">The value of the property that is changed.</param>
14-
public sealed class PropertyChangedEventArgs<T>(string name, T value) : PropertyChangedEventArgs(name)
11+
public sealed class PropertyChangedEventArgs<T>(string? propertyName, T value) : PropertyChangedEventArgs(propertyName)
1512
{
13+
/// <remarks>
14+
/// Initializes a instance of the <see cref="PropertyChangedEventArgs{T}"/> class.
15+
/// </remarks>
16+
/// <param name="value">The value of the property that is changed.</param>
17+
public PropertyChangedEventArgs(T value) : this(null, value)
18+
=> Value = value;
19+
1620
/// <summary>
1721
/// The value of the property that is changed.
1822
/// </summary>

src/BB84.Notifications/Components/PropertyChangingEventArgs.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
namespace BB84.Notifications.Components;
44

55
/// <summary>
6-
/// The property changing event args class.
6+
/// Provides data for the <see cref="INotifyPropertyChanging"/> event.
77
/// </summary>
88
/// <typeparam name="T">The type to work with.</typeparam>
9-
/// <remarks>
10-
/// Initializes a instance of the property changing event args class.
11-
/// </remarks>
12-
/// <param name="name">The name of the property that is changing.</param>
9+
/// <param name="propertyName">The name of the property that is changing.</param>
1310
/// <param name="value">The value of the property that is changing.</param>
14-
public sealed class PropertyChangingEventArgs<T>(string name, T value) : PropertyChangingEventArgs(name)
11+
public sealed class PropertyChangingEventArgs<T>(string? propertyName, T value) : PropertyChangingEventArgs(propertyName)
1512
{
13+
/// <summary>
14+
/// Initializes a instance of the <see cref="PropertyChangingEventArgs{T}"/> class.
15+
/// </summary>
16+
/// <param name="value">The value of the property that is changing.</param>
17+
public PropertyChangingEventArgs(T value) : this(null, value)
18+
=> Value = value;
19+
1620
/// <summary>
1721
/// The value of the property that is changing.
1822
/// </summary>

src/BB84.Notifications/Interfaces/INotificationCollection.cs src/BB84.Notifications/Interfaces/INotifiableCollection.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
namespace BB84.Notifications.Interfaces;
77

88
/// <summary>
9-
/// The notification collection interface.
9+
/// The notifiable collection interface.
1010
/// </summary>
1111
[SuppressMessage("Naming", "CA1711", Justification = "Identifier is correct here")]
12-
public interface INotificationCollection : INotifyCollectionChanged, INotifyCollectionChanging, INotifyPropertyChanged, INotifyPropertyChanging
12+
public interface INotifiableCollection : INotifyCollectionChanged, INotifyCollectionChanging, INotifyPropertyChanged, INotifyPropertyChanging
1313
{ }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.ComponentModel;
2+
3+
namespace BB84.Notifications.Interfaces;
4+
5+
/// <summary>
6+
/// The notifiable object interface.
7+
/// </summary>
8+
public interface INotifiableObject : INotifyPropertyChanged, INotifyPropertyChanging
9+
{ }

src/BB84.Notifications/Interfaces/IBindableProperty.cs src/BB84.Notifications/Interfaces/INotifiableProperty.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
namespace BB84.Notifications.Interfaces;
44

55
/// <summary>
6-
/// The bindable property interface.
6+
/// The notifiable property interface.
77
/// </summary>
88
/// <typeparam name="T">The value type to work with.</typeparam>
9-
public interface IBindableProperty<T> : INotifyPropertyChanged, INotifyPropertyChanging
9+
public interface INotifiableProperty<T> : INotifyPropertyChanged, INotifyPropertyChanging
1010
{
1111
/// <summary>
12-
/// Is the value of the bindable property the default value?
12+
/// Is the value of the notifiable property the default value?
1313
/// </summary>
1414
bool IsDefault { get; }
1515

1616
/// <summary>
17-
/// Is the value of the bindable property null?
17+
/// Is the value of the notifiable property null?
1818
/// </summary>
1919
bool IsNull { get; }
2020

2121
/// <summary>
22-
/// The actual value of the bindable property.
22+
/// The actual value of the notifiable property.
2323
/// </summary>
2424
T Value { get; set; }
2525
}

src/BB84.Notifications/Interfaces/INotificationObject.cs

-9
This file was deleted.

src/BB84.Notifications/NotificationCollection.cs src/BB84.Notifications/NotifiableCollection.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
namespace BB84.Notifications;
88

99
/// <summary>
10-
/// The notification collection class.
10+
/// The notifiable collection class.
1111
/// </summary>
1212
[SuppressMessage("Naming", "CA1711", Justification = "Identifier is correct here")]
13-
public abstract class NotificationCollection : NotificationObject, INotificationCollection
13+
public abstract class NotifiableCollection : NotifiableObject, INotifiableCollection
1414
{
1515
/// <inheritdoc/>
1616
public event CollectionChangedEventHandler? CollectionChanged;

src/BB84.Notifications/NotificationObject.cs src/BB84.Notifications/NotifiableObject.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
namespace BB84.Notifications;
1010

1111
/// <summary>
12-
/// The notification object class.
12+
/// The notifiable object class.
1313
/// </summary>
14-
public abstract class NotificationObject : INotificationObject
14+
public abstract class NotifiableObject : INotifiableObject
1515
{
1616
/// <inheritdoc/>
1717
public event PropertyChangedEventHandler? PropertyChanged;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.ComponentModel;
2+
3+
using BB84.Notifications.Components;
4+
using BB84.Notifications.Interfaces;
5+
6+
namespace BB84.Notifications;
7+
8+
/// <summary>
9+
/// The notifiable property class.
10+
/// </summary>
11+
/// <typeparam name="T">The value type to work with.</typeparam>
12+
/// <inheritdoc/>
13+
/// <param name="value">The value of the notifiable property.</param>
14+
public sealed class NotifiableProperty<T>(T value) : INotifiableProperty<T>
15+
{
16+
private T _value = value;
17+
18+
/// <inheritdoc/>
19+
public bool IsDefault => EqualityComparer<T>.Default.Equals(_value, default!);
20+
21+
/// <inheritdoc/>
22+
public bool IsNull => _value is null;
23+
24+
/// <inheritdoc/>
25+
public T Value
26+
{
27+
get => _value;
28+
set => SetProperty(ref _value, value);
29+
}
30+
31+
/// <inheritdoc/>
32+
public event PropertyChangedEventHandler? PropertyChanged;
33+
34+
/// <inheritdoc/>
35+
public event PropertyChangingEventHandler? PropertyChanging;
36+
37+
/// <summary>
38+
/// Sets the new value the property and notifies about the change.
39+
/// </summary>
40+
/// <param name="fieldValue">The referenced value field.</param>
41+
/// <param name="newValue">The new value for the property.</param>
42+
private void SetProperty(ref T fieldValue, T newValue)
43+
{
44+
if (!EqualityComparer<T>.Default.Equals(fieldValue, newValue))
45+
{
46+
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs<T>(fieldValue));
47+
fieldValue = newValue;
48+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs<T>(newValue));
49+
}
50+
}
51+
}

src/BB84.Notifications/ValidatableObject.cs

+5-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace BB84.Notifications;
88
/// <summary>
99
/// The validatable object class.
1010
/// </summary>
11-
public abstract class ValidatableObject : NotificationObject, Interfaces.IValidatableObject
11+
public abstract class ValidatableObject : NotifiableObject, Interfaces.IValidatableObject
1212
{
1313
private readonly Dictionary<string, List<string?>> _errors = [];
1414

@@ -21,20 +21,13 @@ public abstract class ValidatableObject : NotificationObject, Interfaces.IValida
2121
#if NET5_0_OR_GREATER
2222
/// <inheritdoc/>
2323
public IEnumerable GetErrors(string? propertyName)
24-
{
25-
if (propertyName is null)
26-
return _errors;
27-
28-
List<string?>? values = [];
29-
return _errors.TryGetValue(propertyName, out values) ? values : Array.Empty<string?>();
30-
}
24+
=> propertyName is null
25+
? _errors
26+
: _errors.TryGetValue(propertyName, out List<string?>? values) ? values : Array.Empty<string?>();
3127
#else
3228
/// <inheritdoc/>
3329
public IEnumerable GetErrors(string propertyName)
34-
{
35-
List<string?> values = [];
36-
return _errors.TryGetValue(propertyName, out values) ? values : Array.Empty<string?>();
37-
}
30+
=> _errors.TryGetValue(propertyName, out List<string?> values) ? values : Array.Empty<string?>();
3831
#endif
3932

4033
/// <summary>

tests/BB84.NotificationsTests/Attributes/NotifyChangedAttributeTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void NotifyChangedAttributeTest()
2020
Assert.AreEqual(nameof(TestClass.TotalValue), propertiesNotified.Last());
2121
}
2222

23-
private sealed class TestClass : NotificationObject
23+
private sealed class TestClass : NotifiableObject
2424
{
2525
private int _quantity;
2626
private int _value;

tests/BB84.NotificationsTests/Attributes/NotifyChangingAttributeTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void NotifyChangingAttributeTest()
2020
Assert.AreEqual(nameof(TestClass.TotalValue), propertiesNotified.Last());
2121
}
2222

23-
private sealed class TestClass : NotificationObject
23+
private sealed class TestClass : NotifiableObject
2424
{
2525
private int _quantity;
2626
private int _value;

tests/BB84.NotificationsTests/NotificationCollectionTests.Add.cs tests/BB84.NotificationsTests/NotifiableCollectionTests.Add.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace BB84.NotificationsTests;
66

7-
public sealed partial class NotificationCollectionTests
7+
public sealed partial class NotifiableCollectionTests
88
{
99
[TestMethod]
1010
public void Adding()

tests/BB84.NotificationsTests/NotificationCollectionTests.Refresh.cs tests/BB84.NotificationsTests/NotifiableCollectionTests.Refresh.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BB84.NotificationsTests;
44

5-
public sealed partial class NotificationCollectionTests
5+
public sealed partial class NotifiableCollectionTests
66
{
77
[TestMethod]
88
public void Refreshing()

tests/BB84.NotificationsTests/NotificationCollectionTests.Remove.cs tests/BB84.NotificationsTests/NotifiableCollectionTests.Remove.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace BB84.NotificationsTests;
66

7-
public sealed partial class NotificationCollectionTests
7+
public sealed partial class NotifiableCollectionTests
88
{
99
[TestMethod]
1010
public void Removing()

tests/BB84.NotificationsTests/NotificationCollectionTests.cs tests/BB84.NotificationsTests/NotifiableCollectionTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
namespace BB84.NotificationsTests;
88

99
[TestClass]
10-
public sealed partial class NotificationCollectionTests
10+
public sealed partial class NotifiableCollectionTests
1111
{
1212
private const string UnitTestString = "UnitTest";
1313

14-
private sealed class MyCollection : NotificationCollection, ICollection<string>
14+
private sealed class MyCollection : NotifiableCollection, ICollection<string>
1515
{
1616
private readonly Collection<string> _collection;
1717

tests/BB84.NotificationsTests/NotificationObjectTests.Changed.cs tests/BB84.NotificationsTests/NotifiableObjectTests.Changed.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BB84.NotificationsTests;
44

5-
public sealed partial class NotificationObjectTests
5+
public sealed partial class NotifiableObjectTests
66
{
77
[TestMethod]
88
public void Changed()

tests/BB84.NotificationsTests/NotificationObjectTests.Changing.cs tests/BB84.NotificationsTests/NotifiableObjectTests.Changing.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BB84.NotificationsTests;
44

5-
public sealed partial class NotificationObjectTests
5+
public sealed partial class NotifiableObjectTests
66
{
77
[TestMethod]
88
public void Changing()

tests/BB84.NotificationsTests/NotificationObjectTests.cs tests/BB84.NotificationsTests/NotifiableObjectTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace BB84.NotificationsTests;
44

55
[TestClass]
6-
public sealed partial class NotificationObjectTests
6+
public sealed partial class NotifiableObjectTests
77
{
8-
private sealed class TestClass : NotificationObject
8+
private sealed class TestClass : NotifiableObject
99
{
1010
private int _property;
1111

tests/BB84.NotificationsTests/BindablePropertyTests.Changed.cs tests/BB84.NotificationsTests/NotifiablePropertyTests.Changed.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BB84.NotificationsTests;
44

5-
public sealed partial class BindablePropertyTests
5+
public sealed partial class NotifiablePropertyTests
66
{
77
[TestMethod]
88
public void Changed()

tests/BB84.NotificationsTests/BindablePropertyTests.Changing.cs tests/BB84.NotificationsTests/NotifiablePropertyTests.Changing.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BB84.NotificationsTests;
44

5-
public sealed partial class BindablePropertyTests
5+
public sealed partial class NotifiablePropertyTests
66
{
77
[TestMethod]
88
public void Changing()

0 commit comments

Comments
 (0)