Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Add CallMemberPropertyName to OnPropertyChanged in view model
Browse files Browse the repository at this point in the history
  • Loading branch information
klemmchr authored May 1, 2022
1 parent c71d563 commit 7835839
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/MvvmBlazor.Core/Internal/Parameters/ParameterCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ internal abstract class WeakEventListenerBase<T, TArgs> : IWeakEventListener whe

protected WeakEventListenerBase(T source, Action<T, TArgs> handler)
{
_source = new WeakReference<T>(source ?? throw new ArgumentNullException(nameof(source)));
_handler = new WeakReference<Action<T, TArgs>>(handler ?? throw new ArgumentNullException(nameof(handler)));
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(handler);

_source = new WeakReference<T>(source);
_handler = new WeakReference<Action<T, TArgs>>(handler);
}

public bool IsAlive => _handler.TryGetTarget(out _) && _source.TryGetTarget(out _);
Expand Down Expand Up @@ -81,12 +84,10 @@ public TypedWeakEventListener(
Action<T, EventHandler<TArgs>> unregister,
Action<T, TArgs> 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!);
}

Expand Down
20 changes: 4 additions & 16 deletions src/MvvmBlazor.Core/Internal/WeakEventListener/WeakEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ public class WeakEventManager : IWeakEventManager
public void AddWeakEventListener<T, TArgs>(T source, string eventName, Action<T, TArgs> handler)
where T : class where TArgs : EventArgs
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

_listeners.Add(new WeakEventListener<T, TArgs>(source, eventName, handler), handler);
}
Expand All @@ -55,10 +52,7 @@ public void AddWeakEventListener<T, TArgs>(T source, string eventName, Action<T,
public void AddWeakEventListener<T>(T source, Action<T, PropertyChangedEventArgs> handler)
where T : class, INotifyPropertyChanged
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

_listeners.Add(new PropertyChangedWeakEventListener<T>(source, handler), handler);
}
Expand All @@ -69,10 +63,7 @@ public void AddWeakEventListener<T>(T source, Action<T, PropertyChangedEventArgs
public void AddWeakEventListener<T>(T source, Action<T, NotifyCollectionChangedEventArgs> handler)
where T : class, INotifyCollectionChanged
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

_listeners.Add(new CollectionChangedWeakEventListener<T>(source, handler), handler);
}
Expand All @@ -82,10 +73,7 @@ public void AddWeakEventListener<T>(T source, Action<T, NotifyCollectionChangedE
/// </summary>
public void RemoveWeakEventListener<T>(T source) where T : class
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

var toRemove = new List<IWeakEventListener>();
foreach (var listener in _listeners.Keys)
Expand Down
3 changes: 2 additions & 1 deletion src/MvvmBlazor.Core/ViewModel/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ protected bool Set<T>(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));
}

Expand Down

0 comments on commit 7835839

Please sign in to comment.