Skip to content

Commit

Permalink
WAF minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Dec 3, 2023
1 parent 1fac4a9 commit 025b261
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Manager : IManager<Publisher, Subscriber>

public class Publisher : IPublisher, INotifyDataErrorInfo
{
private static readonly DataErrorsChangedEventArgs args = new DataErrorsChangedEventArgs("Test");
private static readonly DataErrorsChangedEventArgs args = new("Test");
private EventHandler<DataErrorsChangedEventArgs>? errorsChanged;

public int EventHandlerCount { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Manager : IManager<Publisher, Subscriber>

public class Publisher : IPublisher
{
private static readonly PropertyChangedEventArgs args = new PropertyChangedEventArgs("Test");
private static readonly PropertyChangedEventArgs args = new("Test");
private EventHandler<PropertyChangedEventArgs>? event1;

public int EventHandlerCount { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WeakReference<Subscriber> Core()
{
var subscriber = new Subscriber();
table.Add((PropertyChangedEventHandler)subscriber.Handler1);
return new WeakReference<Subscriber>(subscriber);
return new(subscriber);
}
}

Expand All @@ -37,7 +37,7 @@ WeakReference<Subscriber> Core()
var subscriber = new Subscriber();
table.Add((PropertyChangedEventHandler)subscriber.Handler1);
table.Remove((PropertyChangedEventHandler)subscriber.Handler1);
return new WeakReference<Subscriber>(subscriber);
return new(subscriber);
}
}

Expand All @@ -58,7 +58,7 @@ WeakReference<Subscriber> Core()
table.Remove((PropertyChangedEventHandler)subscriber.Handler1);
table.Remove((PropertyChangedEventHandler)subscriber.Handler2);
table.Remove((PropertyChangedEventHandler)Subscriber.StaticHandler);
return new WeakReference<Subscriber>(subscriber);
return new(subscriber);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Manager : IManager<Publisher, Subscriber>

public class Publisher : IPublisher, INotifyPropertyChanged
{
private static readonly PropertyChangedEventArgs args = new PropertyChangedEventArgs("Test");
private static readonly PropertyChangedEventArgs args = new("Test");
private PropertyChangedEventHandler? propertyChanged;

public int EventHandlerCount { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static (WeakReference<Manager>, WeakReference<Subscriber>) WeakEventHand
Assert.AreEqual(count, subscriber.HandlerCallCount);
}

return (new WeakReference<Manager>(manager), new WeakReference<Subscriber>(subscriber));
return (new(manager), new(subscriber));
}

public class Manager
Expand All @@ -126,7 +126,7 @@ public class Manager

public static class StaticPublisher
{
private static readonly PropertyChangedEventArgs args = new PropertyChangedEventArgs("Test");
private static readonly PropertyChangedEventArgs args = new("Test");
private static EventHandler<PropertyChangedEventArgs>? event1;

public static int EventHandlerCount { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static (WeakReference<Manager>, WeakReference<Subscriber>) WeakEventHand
Assert.AreEqual(count, subscriber.HandlerCallCount);
}

return (new WeakReference<Manager>(manager), new WeakReference<Subscriber>(subscriber));
return (new(manager), new(subscriber));
}

public class Manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static (WeakReference<TManager>, WeakReference<TPublisher>, WeakReferenc
Assert.AreEqual(count, subscriber.HandlerCallCount);
}

return (new WeakReference<TManager>(manager), new WeakReference<TPublisher>(publisher), new WeakReference<TSubscriber>(subscriber));
return (new(manager), new(publisher), new(subscriber));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IWeakEventProxy
/// </remarks>
public static class WeakEvent
{
private static readonly WeakEventHandlerTable weakTable = new WeakEventHandlerTable();
private static readonly WeakEventHandlerTable weakTable = new();

/// <summary>Supports listening to EventHandler events via a weak reference.</summary>
public static class EventHandler
Expand Down Expand Up @@ -57,8 +57,8 @@ private sealed class WeakEventProxy<TSource> : IWeakEventProxy where TSource : c

public WeakEventProxy(TSource source, S.EventHandler targetHandler, Action<TSource, S.EventHandler> subscribe, Action<TSource, S.EventHandler> unsubscribe)
{
this.source = new WeakReference<TSource>(source);
weakTargetHandler = new WeakReference<S.EventHandler>(targetHandler);
this.source = new(source);
weakTargetHandler = new(targetHandler);
this.unsubscribe = unsubscribe;
subscribe(source, ProxyHandler);
weakTable.Add(targetHandler);
Expand Down Expand Up @@ -114,8 +114,8 @@ private sealed class WeakEventProxy<TSource> : IWeakEventProxy where TSource : c

public WeakEventProxy(TSource source, S.EventHandler<TArgs> targetHandler, Action<TSource, S.EventHandler<TArgs>> subscribe, Action<TSource, S.EventHandler<TArgs>> unsubscribe)
{
this.source = new WeakReference<TSource>(source);
weakTargetHandler = new WeakReference<S.EventHandler<TArgs>>(targetHandler);
this.source = new(source);
weakTargetHandler = new(targetHandler);
this.unsubscribe = unsubscribe;
subscribe(source, ProxyHandler);
weakTable.Add(targetHandler);
Expand Down Expand Up @@ -165,7 +165,7 @@ private sealed class WeakEventProxy : IWeakEventProxy

public WeakEventProxy(S.EventHandler targetHandler, Action<S.EventHandler> subscribe, Action<S.EventHandler> unsubscribe)
{
weakTargetHandler = new WeakReference<S.EventHandler>(targetHandler);
weakTargetHandler = new(targetHandler);
this.unsubscribe = unsubscribe;
subscribe(ProxyHandler);
weakTable.Add(targetHandler);
Expand Down Expand Up @@ -216,7 +216,7 @@ private sealed class WeakEventProxy : IWeakEventProxy

public WeakEventProxy(S.EventHandler<TArgs> targetHandler, Action<S.EventHandler<TArgs>> subscribe, Action<S.EventHandler<TArgs>> unsubscribe)
{
weakTargetHandler = new WeakReference<S.EventHandler<TArgs>>(targetHandler);
weakTargetHandler = new(targetHandler);
this.unsubscribe = unsubscribe;
subscribe(ProxyHandler);
weakTable.Add(targetHandler);
Expand Down Expand Up @@ -265,8 +265,8 @@ private sealed class WeakEventProxy : IWeakEventProxy

public WeakEventProxy(INotifyPropertyChanged source, PropertyChangedEventHandler targetHandler, Action<INotifyPropertyChanged, PropertyChangedEventHandler> subscribe, Action<INotifyPropertyChanged, PropertyChangedEventHandler> unsubscribe)
{
this.source = new WeakReference<INotifyPropertyChanged>(source);
weakTargetHandler = new WeakReference<PropertyChangedEventHandler>(targetHandler);
this.source = new(source);
weakTargetHandler = new(targetHandler);
this.unsubscribe = unsubscribe;
subscribe(source, ProxyHandler);
weakTable.Add(targetHandler);
Expand Down

0 comments on commit 025b261

Please sign in to comment.