Skip to content

Commit a869b29

Browse files
glennawatsonMatej Hrlec
andauthored
fix: Improve null handling in DefaultViewLocator (#2919)
Co-authored-by: Matej Hrlec <matej.hrlec@inel.com>
1 parent 2be5893 commit a869b29

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/ReactiveUI/View/DefaultViewLocator.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal DefaultViewLocator(Func<string, string>? viewModelToViewFunc = null) =>
111111
return view;
112112
}
113113

114-
view = AttemptViewResolutionFor(ToggleViewModelType(viewModel?.GetType()), contract);
114+
view = AttemptViewResolutionFor(ToggleViewModelType(viewModel.GetType()), contract);
115115

116116
if (view is not null)
117117
{
@@ -129,13 +129,8 @@ internal DefaultViewLocator(Func<string, string>? viewModelToViewFunc = null) =>
129129
return null;
130130
}
131131

132-
private static Type? ToggleViewModelType(Type? viewModelType)
132+
private static Type? ToggleViewModelType(Type viewModelType)
133133
{
134-
if (viewModelType is null)
135-
{
136-
return null;
137-
}
138-
139134
var viewModelTypeName = viewModelType.AssemblyQualifiedName;
140135

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

202-
if (view is not null)
203-
{
204-
return view;
205-
}
206-
207-
return null;
197+
return view;
208198
}
209199

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

220210
var service = Locator.Current.GetService(viewType, contract);
221-
if (service is null)
222-
{
223-
return null;
224-
}
225211

226212
if (service is not IViewFor view)
227213
{

0 commit comments

Comments
 (0)