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

refactor: interface and class naming #77

Merged
merged 2 commits into from
Mar 25, 2024
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
46 changes: 0 additions & 46 deletions src/BB84.Notifications/BindableProperty.cs

This file was deleted.

10 changes: 2 additions & 8 deletions src/BB84.Notifications/Components/CollectionChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
namespace BB84.Notifications.Components;

/// <summary>
/// The collection changed event args class.
/// Provides data for the <see cref="INotifyCollectionChanged"/> event.
/// </summary>
/// <remarks>
/// Initializes a instance of the collection changed event args class.
/// </remarks>
/// <param name="action">The action that causes the change.</param>
public class CollectionChangedEventArgs(CollectionChangeAction action) : EventArgs
{
Expand All @@ -21,12 +18,9 @@ public class CollectionChangedEventArgs(CollectionChangeAction action) : EventAr
}

/// <summary>
/// The collection changed event args class.
/// Provides data for the <see cref="INotifyCollectionChanged"/> event.
/// </summary>
/// <typeparam name="T">The type to work with.</typeparam>
/// <remarks>
/// Initializes a instance of the collection changed event args class.
/// </remarks>
/// <param name="action">The action that causes the change.</param>
/// <param name="item">The item that is changed.</param>
public sealed class CollectionChangedEventArgs<T>(CollectionChangeAction action, T item) : CollectionChangedEventArgs(action)
Expand Down
10 changes: 2 additions & 8 deletions src/BB84.Notifications/Components/CollectionChangingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
namespace BB84.Notifications.Components;

/// <summary>
/// The collection changing event args class.
/// Provides data for the <see cref="INotifyCollectionChanging"/> event.
/// </summary>
/// <remarks>
/// Initializes a instance of the collection changing event args class.
/// </remarks>
/// <param name="action">The action that causes the change.</param>
public class CollectionChangingEventArgs(CollectionChangeAction action) : EventArgs
{
Expand All @@ -21,12 +18,9 @@ public class CollectionChangingEventArgs(CollectionChangeAction action) : EventA
}

/// <summary>
/// The collection changing event args class.
/// Provides data for the <see cref="INotifyCollectionChanging"/> event.
/// </summary>
/// <typeparam name="T">The type to work with.</typeparam>
/// <remarks>
/// Initializes a instance of the collection changing event args class.
/// </remarks>
/// <param name="action">The action that causes the change.</param>
/// <param name="item">The item that is changing.</param>
public sealed class CollectionChangingEventArgs<T>(CollectionChangeAction action, T item) : CollectionChangingEventArgs(action)
Expand Down
16 changes: 10 additions & 6 deletions src/BB84.Notifications/Components/PropertyChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
namespace BB84.Notifications.Components;

/// <summary>
/// The property changed event args class.
/// Provides data for the <see cref="INotifyPropertyChanged"/> event.
/// </summary>
/// <typeparam name="T">The type to work with.</typeparam>
/// <remarks>
/// Initializes a instance of the property changed event args class.
/// </remarks>
/// <param name="name">The name of the property that is changed.</param>
/// <param name="propertyName">The name of the property that is changed.</param>
/// <param name="value">The value of the property that is changed.</param>
public sealed class PropertyChangedEventArgs<T>(string name, T value) : PropertyChangedEventArgs(name)
public sealed class PropertyChangedEventArgs<T>(string? propertyName, T value) : PropertyChangedEventArgs(propertyName)
{
/// <remarks>
/// Initializes a instance of the <see cref="PropertyChangedEventArgs{T}"/> class.
/// </remarks>
/// <param name="value">The value of the property that is changed.</param>
public PropertyChangedEventArgs(T value) : this(null, value)
=> Value = value;

/// <summary>
/// The value of the property that is changed.
/// </summary>
Expand Down
16 changes: 10 additions & 6 deletions src/BB84.Notifications/Components/PropertyChangingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
namespace BB84.Notifications.Components;

/// <summary>
/// The property changing event args class.
/// Provides data for the <see cref="INotifyPropertyChanging"/> event.
/// </summary>
/// <typeparam name="T">The type to work with.</typeparam>
/// <remarks>
/// Initializes a instance of the property changing event args class.
/// </remarks>
/// <param name="name">The name of the property that is changing.</param>
/// <param name="propertyName">The name of the property that is changing.</param>
/// <param name="value">The value of the property that is changing.</param>
public sealed class PropertyChangingEventArgs<T>(string name, T value) : PropertyChangingEventArgs(name)
public sealed class PropertyChangingEventArgs<T>(string? propertyName, T value) : PropertyChangingEventArgs(propertyName)
{
/// <summary>
/// Initializes a instance of the <see cref="PropertyChangingEventArgs{T}"/> class.
/// </summary>
/// <param name="value">The value of the property that is changing.</param>
public PropertyChangingEventArgs(T value) : this(null, value)
=> Value = value;

/// <summary>
/// The value of the property that is changing.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace BB84.Notifications.Interfaces.Components;

/// <summary>
/// The notify collection changed interface.
/// Notifies clients that a collection has changed.
/// </summary>
public interface INotifyCollectionChanged
{
/// <summary>
/// Occurs when the collection is changed.
/// Occurs when a collection changes.
/// </summary>
event CollectionChangedEventHandler? CollectionChanged;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace BB84.Notifications.Interfaces.Components;

/// <summary>
/// The notify collection changing interface.
/// Notifies clients that a collection is changing.
/// </summary>
public interface INotifyCollectionChanging
{
/// <summary>
/// Occurs when the collection is changing.
/// Occurs when a collection is changing.
/// </summary>
event CollectionChangingEventHandler? CollectionChanging;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
namespace BB84.Notifications.Interfaces;

/// <summary>
/// The notification collection interface.
/// The notifiable collection interface.
/// </summary>
[SuppressMessage("Naming", "CA1711", Justification = "Identifier is correct here")]
public interface INotificationCollection : INotifyCollectionChanged, INotifyCollectionChanging, INotifyPropertyChanged, INotifyPropertyChanging
public interface INotifiableCollection : INotifyCollectionChanged, INotifyCollectionChanging, INotifyPropertyChanged, INotifyPropertyChanging
{ }
9 changes: 9 additions & 0 deletions src/BB84.Notifications/Interfaces/INotifiableObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.ComponentModel;

namespace BB84.Notifications.Interfaces;

/// <summary>
/// The notifiable object interface.
/// </summary>
public interface INotifiableObject : INotifyPropertyChanged, INotifyPropertyChanging
{ }
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
namespace BB84.Notifications.Interfaces;

/// <summary>
/// The bindable property interface.
/// The notifiable property interface.
/// </summary>
/// <typeparam name="T">The value type to work with.</typeparam>
public interface IBindableProperty<T> : INotifyPropertyChanged, INotifyPropertyChanging
public interface INotifiableProperty<T> : INotifyPropertyChanged, INotifyPropertyChanging
{
/// <summary>
/// Is the value of the bindable property the default value?
/// Is the value of the notifiable property the default value?
/// </summary>
bool IsDefault { get; }

/// <summary>
/// Is the value of the bindable property null?
/// Is the value of the notifiable property null?
/// </summary>
bool IsNull { get; }

/// <summary>
/// The actual value of the bindable property.
/// The actual value of the notifiable property.
/// </summary>
T Value { get; set; }
}
9 changes: 0 additions & 9 deletions src/BB84.Notifications/Interfaces/INotificationObject.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
namespace BB84.Notifications;

/// <summary>
/// The notification collection class.
/// The notifiable collection class.
/// </summary>
[SuppressMessage("Naming", "CA1711", Justification = "Identifier is correct here")]
public abstract class NotificationCollection : NotificationObject, INotificationCollection
public abstract class NotifiableCollection : NotifiableObject, INotifiableCollection
{
/// <inheritdoc/>
public event CollectionChangedEventHandler? CollectionChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace BB84.Notifications;

/// <summary>
/// The notification object class.
/// The notifiable object class.
/// </summary>
public abstract class NotificationObject : INotificationObject
public abstract class NotifiableObject : INotifiableObject
{
/// <inheritdoc/>
public event PropertyChangedEventHandler? PropertyChanged;
Expand Down
51 changes: 51 additions & 0 deletions src/BB84.Notifications/NotifiableProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.ComponentModel;

using BB84.Notifications.Components;
using BB84.Notifications.Interfaces;

namespace BB84.Notifications;

/// <summary>
/// The notifiable property class.
/// </summary>
/// <typeparam name="T">The value type to work with.</typeparam>
/// <inheritdoc/>
/// <param name="value">The value of the notifiable property.</param>
public sealed class NotifiableProperty<T>(T value) : INotifiableProperty<T>
{
private T _value = value;

/// <inheritdoc/>
public bool IsDefault => EqualityComparer<T>.Default.Equals(_value, default!);

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

/// <inheritdoc/>
public T Value
{
get => _value;
set => SetProperty(ref _value, value);
}

/// <inheritdoc/>
public event PropertyChangedEventHandler? PropertyChanged;

/// <inheritdoc/>
public event PropertyChangingEventHandler? PropertyChanging;

/// <summary>
/// Sets the new value the property and notifies about the change.
/// </summary>
/// <param name="fieldValue">The referenced value field.</param>
/// <param name="newValue">The new value for the property.</param>
private void SetProperty(ref T fieldValue, T newValue)
{
if (!EqualityComparer<T>.Default.Equals(fieldValue, newValue))
{
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs<T>(fieldValue));
fieldValue = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs<T>(newValue));
}
}
}
17 changes: 5 additions & 12 deletions src/BB84.Notifications/ValidatableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BB84.Notifications;
/// <summary>
/// The validatable object class.
/// </summary>
public abstract class ValidatableObject : NotificationObject, Interfaces.IValidatableObject
public abstract class ValidatableObject : NotifiableObject, Interfaces.IValidatableObject
{
private readonly Dictionary<string, List<string?>> _errors = [];

Expand All @@ -21,20 +21,13 @@ public abstract class ValidatableObject : NotificationObject, Interfaces.IValida
#if NET5_0_OR_GREATER
/// <inheritdoc/>
public IEnumerable GetErrors(string? propertyName)
{
if (propertyName is null)
return _errors;

List<string?>? values = [];
return _errors.TryGetValue(propertyName, out values) ? values : Array.Empty<string?>();
}
=> propertyName is null
? _errors
: _errors.TryGetValue(propertyName, out List<string?>? values) ? values : Array.Empty<string?>();
#else
/// <inheritdoc/>
public IEnumerable GetErrors(string propertyName)
{
List<string?> values = [];
return _errors.TryGetValue(propertyName, out values) ? values : Array.Empty<string?>();
}
=> _errors.TryGetValue(propertyName, out List<string?> values) ? values : Array.Empty<string?>();
#endif

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void NotifyChangedAttributeTest()
Assert.AreEqual(nameof(TestClass.TotalValue), propertiesNotified.Last());
}

private sealed class TestClass : NotificationObject
private sealed class TestClass : NotifiableObject
{
private int _quantity;
private int _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void NotifyChangingAttributeTest()
Assert.AreEqual(nameof(TestClass.TotalValue), propertiesNotified.Last());
}

private sealed class TestClass : NotificationObject
private sealed class TestClass : NotifiableObject
{
private int _quantity;
private int _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BB84.NotificationsTests;

public sealed partial class NotificationCollectionTests
public sealed partial class NotifiableCollectionTests
{
[TestMethod]
public void Adding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BB84.NotificationsTests;

public sealed partial class NotificationCollectionTests
public sealed partial class NotifiableCollectionTests
{
[TestMethod]
public void Refreshing()
Expand Down
Loading