diff --git a/src/MvvmBlazor.Core/Internal/Parameters/ParameterCache.cs b/src/MvvmBlazor.Core/Internal/Parameters/ParameterCache.cs index 2e2d87b..fda9a22 100644 --- a/src/MvvmBlazor.Core/Internal/Parameters/ParameterCache.cs +++ b/src/MvvmBlazor.Core/Internal/Parameters/ParameterCache.cs @@ -19,6 +19,7 @@ internal class ParameterCache : IParameterCache public void Set(Type type, ParameterInfo info) { - _cache[type] = info ?? throw new ArgumentNullException(nameof(info)); + ArgumentNullException.ThrowIfNull(info); + _cache[type] = info; } } \ No newline at end of file diff --git a/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventListener.cs b/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventListener.cs index 40267b8..3e0c52d 100644 --- a/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventListener.cs +++ b/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventListener.cs @@ -15,8 +15,11 @@ internal abstract class WeakEventListenerBase : IWeakEventListener whe protected WeakEventListenerBase(T source, Action handler) { - _source = new WeakReference(source ?? throw new ArgumentNullException(nameof(source))); - _handler = new WeakReference>(handler ?? throw new ArgumentNullException(nameof(handler))); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(handler); + + _source = new WeakReference(source); + _handler = new WeakReference>(handler); } public bool IsAlive => _handler.TryGetTarget(out _) && _source.TryGetTarget(out _); @@ -81,12 +84,10 @@ public TypedWeakEventListener( Action> unregister, Action handler) : base(source, handler) { - if (register == null) - { - throw new ArgumentNullException(nameof(register)); - } + ArgumentNullException.ThrowIfNull(register); + ArgumentNullException.ThrowIfNull(unregister); - _unregister = unregister ?? throw new ArgumentNullException(nameof(unregister)); + _unregister = unregister; register(source, HandleEvent!); } diff --git a/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventManager.cs b/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventManager.cs index b41c241..b0d340f 100644 --- a/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventManager.cs +++ b/src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventManager.cs @@ -41,10 +41,7 @@ public class WeakEventManager : IWeakEventManager public void AddWeakEventListener(T source, string eventName, Action handler) where T : class where TArgs : EventArgs { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); _listeners.Add(new WeakEventListener(source, eventName, handler), handler); } @@ -55,10 +52,7 @@ public void AddWeakEventListener(T source, string eventName, Action(T source, Action handler) where T : class, INotifyPropertyChanged { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); _listeners.Add(new PropertyChangedWeakEventListener(source, handler), handler); } @@ -69,10 +63,7 @@ public void AddWeakEventListener(T source, Action(T source, Action handler) where T : class, INotifyCollectionChanged { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); _listeners.Add(new CollectionChangedWeakEventListener(source, handler), handler); } @@ -82,10 +73,7 @@ public void AddWeakEventListener(T source, Action public void RemoveWeakEventListener(T source) where T : class { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); var toRemove = new List(); foreach (var listener in _listeners.Keys) diff --git a/src/MvvmBlazor.Core/ViewModel/ViewModelBase.cs b/src/MvvmBlazor.Core/ViewModel/ViewModelBase.cs index 766e871..a8f48ac 100644 --- a/src/MvvmBlazor.Core/ViewModel/ViewModelBase.cs +++ b/src/MvvmBlazor.Core/ViewModel/ViewModelBase.cs @@ -26,8 +26,9 @@ protected bool Set(ref T field, T value, [CallerMemberName] string? propertyN return false; } - public virtual void OnPropertyChanged(string propertyName) + public virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { + ArgumentNullException.ThrowIfNull(propertyName); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }