The following is done in a console app, only difference is I print out data to the console rather than set label text.
And since I don't have the code for geo location and the code for the catch I simply mocked things up.
The return type of GetLocationDetails
is a named value tuple which we deconstruct by the caller.
internal class Program
{
static async Task Main(string[] args)
{
var (latitude, longitude, countryCode, countryName, exception)
= await GetCurrentLocation.GetLocationDetails();
if (exception is null)
{
Console.WriteLine($"{latitude.Value}, {longitude}, {countryCode}, {countryName}");
}
else
{
Console.WriteLine(exception.Message);
}
}
}
public class GetCurrentLocation
{
public static async Task<(decimal? latitude, decimal? longitude, string countryCode, string countryName, Exception exception)> GetLocationDetails()
{
try
{
await Task.Delay(0);
return (45.103760m, -123.984375m, "en", "usa", null);
}
catch (Exception ex)
{
return (null, null, null, null, ex);
throw;
}
}
}