One suggestion is to reorganize the above code to use the LINQ and lambdas method chains (personal preferences) and then extract the selected lambda into a separate method. For example:
Additionally, if you want to call GetValueOrDefault () for each HHxx property, you can wrap this in an additional helper function. it really comes down to code preference. Which do you prefer? Seeing .GetValueOrDefault () at the end of every access to a resource or function around it? eg
return x.HH01 + x.HH16 + x.HH17 + x.HH18
becomes
return Get(x.HH01) + Get(x.HH16) + Get(x.HH17) + Get(x.HH18) ... private static HClassType Get(HClassType input) { return input.GetValueOrDefault(); }
Personally, I would just go with the HHxx + HHyy code order in the columns and call .GetValueOrDefault () for each of them. If it places the helper method at least once it is only once, even if it is verbose.
Yours faithfully,
Dr. Abt
source share