Я получаю это сообщение об ошибке в последней строке метода OnPlayFabError:
return output;
Ошибка CS0029: невозможно неявно преобразовать тип 'string' в 'System.Threading.Tasks.Task'
Что не так с выводом строки return ;? Я хочу получить значение переменной «output» в этой строке:
error = errormessage.Result;
Что не так с моим кодом?
MainClass.cs:
string Countryname = string.Empty;
string Cityname = string.Empty;
string Errormessage = string.Empty;
var GotNames = await Extensionmethods.GetPlayerCountryData(PlayerPlayFabID, "Country", "City");
Countryname = GotNames.countryname;
Cityname = GotNames.cityname;
Errormessage = GotNames.error;
Extensionmethods.cs:
public static class Extensionmethods
{
public static async Task<(string error, string countryname, string cityname)> GetPlayerCountryData(this string playerplayfabid, string country, string city)
{
string error = string.Empty;
string countryname = string.Empty;
string cityname = string.Empty;
var resultprofile = await PlayFabClientAPI.GetUserDataAsync(new PlayFab.ClientModels.GetUserDataRequest()
{
PlayFabId = playerplayfabid,
Keys = null
});
if (resultprofile.Error != null)
{
// Handle error if any
var errormessage = OnPlayFabError(resultprofile.Error);
error = errormessage.Result;
}
else
{
if (resultprofile.Result.Data == null || !resultprofile.Result.Data.ContainsKey(country) || !resultprofile.Result.Data.ContainsKey(city))
Console.WriteLine("No Country/City");
else
{
countryname = resultprofile.Result.Data[country].Value;
cityname = resultprofile.Result.Data[city].Value;
}
}
return (error, countryname, cityname);
}
public static Task<string> OnPlayFabError(this PlayFabError obj)
{
string output = string.Empty;
switch (obj.Error)
{
case PlayFabErrorCode.AccountBanned:
output = "Account is banned." + "Hier die geladenen Daten aus der Textdatei anzeigen.";
break;
case PlayFabErrorCode.EmailAddressNotAvailable:
output = "E-mail address is already in use. Please choose another e-mail address.";
break;
case PlayFabErrorCode.InvalidParams:
output = "Please fill out all the text fields.";
break;
case PlayFabErrorCode.InvalidUsernameOrPassword:
output = "Wrong username or password.";
break;
case PlayFabErrorCode.UsernameNotAvailable:
output = "Username not available. Please choose another username.";
break;
case PlayFabErrorCode.ConnectionError:
output = "Connection error. Please check your network connection.";
break;
default:
output = "Unknown error!";
break;
}
return output;
}
}