I'm having trouble with poorly named properties:
public class Word
{
public string Alt01 { get;set; }
public string Alt02 { get;set; }
public string Alt03 { get;set; }
public string Alt04 { get;set; }
public string Alt05 { get;set; }
}
This should probably have been one property of the type List<string>
. But someone else came up with this idea, and I can't change the structure at the moment.
I have a method that returns a lot of Word
objects. What I would like to do is to filter out each Word
instance that has a matching string in one or more of the AltXX
properties.
This is what I have so far:
foreach(var word in resultList) //<-- List<Word>
{
var alt01 = word.GetType().GetProperty("alt01").GetValue(word, null);
}
This would work as my filter if I extend it a bit. But my question is: Is this solvable using lambda expressions?