Skip to main content
1 of 3
rolfl
  • 98.1k
  • 17
  • 220
  • 419

Two code-style issues are immediately obvious:

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

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:

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