I just found out I’m not as fluent with delegate and action and the other one as I would want…
I have a certain IEnumerable<T> which I would like to transform to a IEnumerable<object> using a delegate function that creates object as an anonymous object. An extension method would come in handy here or might already exist?
This (or something like this) should be possible right?
IEnumerable<SomeBllObject> list;
IEnumerable<object> newList = list.Transform(x => return new {
someprop = x.SomeProp,
otherprop = x.OtherProp
});
If you’re using .NET 4, you’ve just described the
Selectmethod:For .NET 3.5 you’d need to cast the result of your delegate, as it doesn’t have generic covariance:
Or use implicitly typed local variables and get a strongly typed sequence: