Skip to content

Commit

Permalink
Resolve Nullability Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
brminnick committed Nov 6, 2019
1 parent a2f992a commit 345b063
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
</ItemGroup>
<Import Project="..\AsyncAwaitBestPractices\AsyncAwaitBestPractices.projitems" Label="Shared" Condition="Exists('..\AsyncAwaitBestPractices\AsyncAwaitBestPractices.projitems')" />
<Import Project="..\AsyncAwaitBestPractices.MVVM\AsyncAwaitBestPractices.MVVM.projitems" Label="Shared" Condition="Exists('..\AsyncAwaitBestPractices.MVVM\AsyncAwaitBestPractices.MVVM.projitems')" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace AsyncAwaitBestPractices
{
static class EventManagerService
{
internal static void AddEventHandler(in string eventName, in object? handlerTarget, in MethodInfo methodInfo, in Dictionary<string, List<Subscription>> eventHandlers)
internal static void AddEventHandler(in string eventName, in object? handlerTarget, in MethodInfo? methodInfo, in Dictionary<string, List<Subscription>> eventHandlers)
{
var doesContainSubscriptions = eventHandlers.TryGetValue(eventName, out List<Subscription> targets);
if (!doesContainSubscriptions)
var doesContainSubscriptions = eventHandlers.TryGetValue(eventName, out List<Subscription>? targets);
if (!doesContainSubscriptions || targets is null)
{
targets = new List<Subscription>();
eventHandlers.Add(eventName, targets);
Expand All @@ -21,18 +21,18 @@ internal static void AddEventHandler(in string eventName, in object? handlerTarg
targets.Add(new Subscription(new WeakReference(handlerTarget), methodInfo));
}

internal static void RemoveEventHandler(in string eventName, in object handlerTarget, in MemberInfo methodInfo, in Dictionary<string, List<Subscription>> eventHandlers)
internal static void RemoveEventHandler(in string eventName, in object? handlerTarget, in MemberInfo? methodInfo, in Dictionary<string, List<Subscription>> eventHandlers)
{
var doesContainSubscriptions = eventHandlers.TryGetValue(eventName, out List<Subscription> subscriptions);
if (!doesContainSubscriptions)
var doesContainSubscriptions = eventHandlers.TryGetValue(eventName, out List<Subscription>? subscriptions);
if (!doesContainSubscriptions || subscriptions is null)
return;

for (int n = subscriptions.Count; n > 0; n--)
{
Subscription current = subscriptions[n - 1];

if (current.Subscriber?.Target != handlerTarget
|| current.Handler.Name != methodInfo.Name)
|| current.Handler.Name != methodInfo?.Name)
{
continue;
}
Expand Down Expand Up @@ -102,7 +102,8 @@ static void AddRemoveEvents(in string eventName, in Dictionary<string, List<Subs
var toRemove = new List<Subscription>();
toRaise = new List<Tuple<object?, MethodInfo>>();

if (eventHandlers.TryGetValue(eventName, out List<Subscription> target))
var doesContainEventName = eventHandlers.TryGetValue(eventName, out List<Subscription>? target);
if (doesContainEventName && target != null)
{
for (int i = 0; i < target.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AsyncAwaitBestPractices
{
internal struct Subscription
{
public Subscription(in WeakReference? subscriber, in MethodInfo handler)
public Subscription(in WeakReference? subscriber, in MethodInfo? handler)
{
Subscriber = subscriber;
Handler = handler ?? throw new ArgumentNullException(nameof(handler));
Expand Down

0 comments on commit 345b063

Please sign in to comment.