c# - How to avoid method length creep when using LINQ and vars -


i'm using vars capture anonymous types selected tables in db. it's great, love it. however, since vars cannot method parameters, technique promotes evolution of overly-long methods cannot decomposed e.g.

... var res1 = (from t1 in dao.t1             select new { t1.id, t1.cost, t1.size }).tolist();  <do stuff res1 ...>   var res2 = (from r1 in res1 r1.cost > 100           select new { r1.id, r1.size }).tolist();  <do stuff res2 ...>   var res3 = (from r2 in res2 r2.size > 5              select new { r2.id }.tolist();  <do stuff res3 ...> 

now afaik can't decompose these selects methods due vars. naturally don't want create named types these intermediary variables that'd clunky , bloaty. i'm stuck excessively long methods, right?

if you're using anonymous type , find wishing use beyond scope of single method, it's time promote anonymous type new named type; use instead of anonymous class information, , can freely extract portions of method out other methods.


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? -