c# - Overloading async methods -


i have scenario in library i'm working on:

i have couple of asynchronous methods should work both on single item , list of items. list version this:

public task<list<result>> readasync(list<objectid> objectids) {   ... } 

what recommended approach write version of readasync works on single item?

public task<result> readasync(objectid objectid) {    list<objectid> objectids = new list<objectid> { objectid };    var result = readasync(objectids);     return ? } 

if want list-based version "standard", implement this:

public async task<result> readasync(objectid objectid) {   list<objectid> objectids = new list<objectid> { objectid };   var results = await readasync(objectids);    return results[0]; } 

if can let instance-based version "standard", , willing return array instead of list, can this:

public task<result[]> readasync(ienumerable<objectid> objectids) {   return task.whenall(objectids.select(id => readasync(id))); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -