In method GeExistingDbList(), what's an easy way to convert from Task<list<object>>
to just list<differentobject>
. I'm getting error:
"foreach statement cannot operate on variables of type
Task<list<Connection>>
. does not contain a public instance or extension definition for GetEnumerator".
Do I have to declare a numerator object: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1579?f1url=%3FappId%3Droslyn%26k%3Dk(CS1579)
public class ExistingDb
{
public string DBName { get; set; }
public Guid Id { get; set; }
}
public List<ExistingDb> GeExistingDbList()
{
List<ExistingDb> existingDbList = new List<ExistingDb>();
Task<List<Connection>> connectionsList = GetConnections(ADMIN_TOKEN);
foreach (var conn in connectionsList)
{
existingDbList.Add(new ExistingDb() {
DBName = conn.DatabaseName, Id = conn.Id });
}
return existingDbList;
}
private async Task<List<Connection>> GetConnections(string authToken)
{
string action = $"connection";
try
{
var result = await GetAsync<List<Connection>>(action, authToken);
return result;
}
catch
{
return null;
}
}