Skip to main content
3 of 3
spelling
Malachi
  • 29.1k
  • 11
  • 87
  • 188

Two code-style issues are immediately obvious:

  1. Use braces for 1-liners
  2. only split lines where it overflows

Code like:

var item = result .SingleOrDefault(e => e == "Order"); if (item != null) baseTypes.Add(item); item = result .SingleOrDefault(e => e == "Motion"); 

Should be

var item = result.SingleOrDefault(e => e == "Order"); if (item != null) { baseTypes.Add(item); } item = result.SingleOrDefault(e => e == "Motion"); 

Then, the logical thing to do to simplify those cascading statements, is to create an array of keys to look for (perhaps by loading from a configuration file, or as a static constant array...):

string[] keys = {"Order", "Motion", .....}; 

then loop through them like:

foreach (string key in keys) { var item = result.SingleOrDefault(e => e == key); if (item != null) { baseTypes.Add(item); } } 
rolfl
  • 98.1k
  • 17
  • 220
  • 419