Skip to content

Commit

Permalink
fix: Improve null handling in DefaultViewLocator (#2919)
Browse files Browse the repository at this point in the history
Co-authored-by: Matej Hrlec <matej.hrlec@inel.com>
  • Loading branch information
glennawatson and Matej Hrlec committed Sep 12, 2021
1 parent 2be5893 commit a869b29
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/ReactiveUI/View/DefaultViewLocator.cs
Expand Up @@ -111,7 +111,7 @@ public sealed class DefaultViewLocator : IViewLocator
return view;
}

view = AttemptViewResolutionFor(ToggleViewModelType(viewModel?.GetType()), contract);
view = AttemptViewResolutionFor(ToggleViewModelType(viewModel.GetType()), contract);

if (view is not null)
{
Expand All @@ -129,13 +129,8 @@ public sealed class DefaultViewLocator : IViewLocator
return null;
}

private static Type? ToggleViewModelType(Type? viewModelType)
private static Type? ToggleViewModelType(Type viewModelType)
{
if (viewModelType is null)
{
return null;
}

var viewModelTypeName = viewModelType.AssemblyQualifiedName;

if (viewModelTypeName is null)
Expand Down Expand Up @@ -199,12 +194,7 @@ private static string InterfaceifyTypeName(string typeName)
proposedViewTypeName = typeof(IViewFor<>).MakeGenericType(viewModelType).AssemblyQualifiedName;
view = AttemptViewResolution(proposedViewTypeName, contract);

if (view is not null)
{
return view;
}

return null;
return view;
}

private IViewFor? AttemptViewResolution(string? viewTypeName, string? contract)
Expand All @@ -218,10 +208,6 @@ private static string InterfaceifyTypeName(string typeName)
}

var service = Locator.Current.GetService(viewType, contract);
if (service is null)
{
return null;
}

if (service is not IViewFor view)
{
Expand Down

0 comments on commit a869b29

Please sign in to comment.