Я хотел бы вернуть строковое значение из метода async. Как я могу это сделать? Метод «getPlayerName» теперь использует async. Но потребитель этого метода ожидает строковое значение.Как вернуть строку из метода async?
public DataTable ToDataTable(List<AuctionInfo> data)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(AuctionInfo));
DataTable table = new DataTable();
// loop into all columns
string propName = "PlayerName";
table.Columns.Add(propName, propName.GetType());
foreach (PropertyDescriptor prop in properties)
{
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
}
// todo add column PlayerName
// loop into all auctions/advertenties
foreach (AuctionInfo auctionInfo in data)
{
DataRow row = table.NewRow();
row["PlayerName"] = getPlayerName(auctionInfo);
// loop into all columns and set value
foreach (PropertyDescriptor prop in properties)
{
// set value of column
row[prop.Name] = prop.GetValue(auctionInfo) ?? DBNull.Value;
}
// add row to datatable
table.Rows.Add(row);
}
return table;
}
private async Task<string> getPlayerName(AuctionInfo auctionInfo)
{
var item = await client.GetItemAsync(auctionInfo);
string fullName = string.Format("{0} {1}", item.FirstName, item.LastName);
return fullName;
}
Как вы это делали для 'GetItemAsync()': добавление 'await' перед' getPlayerName() 'в вызывающем сайте? –