I have the following code at the top of 90% of my OnInitializedAsync()
calls and it so calls for the equivilent of a TryGetUserAsync( ... out user)
. Is there a way to make this cleaner/tighter?
User _user;
var tryUser = await UserManager.GetUserAsync(Principal);
if (tryUser == null)
{
Navigation.NavigateTo(GlobalConstants.UrlLogIn, true);
return;
}
_user = tryUser;
Part of the issue here is _user is declared as non-nullable as this is the first thing I do in OnInitializedAsync()
and so I avoid all the nullable warnings when I use it. But if I could have out _user
then inside the TryGetUserAsync
I could call the navigation, return false and the calling code would return.
Any way to do this?