Select execution time of columns in LINQ LIST <>
I want to select some dynamic columns that are not known at compile time, for example:
var result = from l listEmployees select ""
But it throws an error:
'System.Linq.Enumerable.Select (System.Collections.Generic.IEnumerable, System.Func)' cannot be deprecated. Try to specify type arguments explicitly.
How do I select only those columns that are defined at runtime?
Here is a really terrible approach that works
var result = from l in listEmployees select l.GetType().GetProperty(propertyName).GetValue(l, null);
Where propertyName is any string you pass at runtime.
Of course, you probably want to extract the bit after being selected as a method and add some validation.