I have a collection of objects to which I'd like to just add a new property. How do I do that with LINQ?
-
var a = from i in ObjectCollection select new {i.prop1, i.prop2, i.prop3, ..., newprop = newProperty}
From John Boker -
@John:
Yes, that's what I came up with too, but I was wondering if there's a way to do it without having to remap all the properties. All I'd really like to do is just "add" the new one.
From Esteban Araya -
I don't think that you can using pure LINQ. However, if you're doing this sort of thing a lot in your code you may be able to make this work with reflection.
From Guy -
@Esteban yeah, i know what you mean but i dont know of another way either, maybe someone else reading this will.
From John Boker -
Why do you want to add the extra property? Or, put a different way, what do you intend to do with the property once you have it in your new IEnumerable source?
If you need it for data binding, I have a helper class that might help you.
jfar : I'd be interested in seeing this helper class.From Lasse V. Karlsen
0 comments:
Post a Comment