A Limitation of Anonymous Classes

Posted by:

Recently, we were editing some code for a client, specifically code that creates a list of an anonymous class, and then runs a LINQ statement on it.

As part of the edit, we had to set the values of this class differently under different conditions. Regardless of the situation, though, the structure would end up the same. We ended up with something similar to this:

If (boolCondition)
var items = itemSourceOne.Select(x => new {id = x.id, value = x.value}).ToList();
else
var items = itemSourceOther.Select(x => ...
Continue Reading →
0