score:5

Accepted answer

you need to unwrap the tasks using, await task.whenall(additionalinformation) then you access the actual result using additionalinformation[0].result.

so something like this:

var additionalinformation=   response.additionalinformation.select( async x =>  new additionalinformationitem
                {
                    statementcode = x?.statementcode?.value,
                    limitdatetime = x?.limitdatetime?.item?.value,
                    statementtypecode = x?.statementtypecode?.value,
                    statementdescription = x?.statementdescription?.value,
                    additionalinformationresult = await buildadditionalinformationpointers(x)


                });

await task.whenall(additionalinformation);
//this will iterate the results so may not be the most efficient method if you have a lot of results
list<additionalinformationitem> unwrapped = additionalinformation.select(s => s.result).tolist();

score:1

there is actually no way to do this in a simple lambda expression. the async lambda expression will always return a task<t>. so you can go quick and dirty and call .result on the task (don't do it! except if you await first as in liam's answer), or simply initialize a new list and add items in a foreach loop:

var additionalinformation = new list<additionalinformationitem>();
foreach (var x in response.additionalinformation)
{
    var item = new additionalinformationitem
        {
            statementcode = x?.statementcode?.value,
            limitdatetime = x?.limitdatetime?.item?.value,
            statementtypecode = x?.statementtypecode?.value,
            statementdescription = x?.statementdescription?.value,
            additionalinformationresult = await buildadditionalinformationpointers(x)
        };

    additionalinformation.add(item);
}

score:1

await task.whenall will automatically unwrap the tasks, and will hand you an array with the results.

additionalinformationitem[] additionalinformation = await task.whenall(
    response.additionalinformation.select(async x => new additionalinformationitem
    {
        statementcode = x?.statementcode?.value,
        limitdatetime = x?.limitdatetime?.item?.value,
        statementtypecode = x?.statementtypecode?.value,
        statementdescription = x?.statementdescription?.value,
        additionalinformationresult = await buildadditionalinformationpointers(x)
    });
);

Related Query

More Query from same tag