Hi,
I often need to augment a object with a property for instance. Until now (tired of it ;) and it's ugly too) I have done it this way:
var someListOfObjects = ...;
var objectsWithMyProperty = from o in someListOfObjects
select new
{
o.Name, /* Just copying all the attributes I need */
o.Address, /* which may be all of them. */
SomeNewProperty = value
};
Is there a clever way to do this? What I have done previously is something like this:
var objectsWithMyProperty = from o in someListOfObjects
select new
{
OldObject = o, /* I access all of the old properties from here */
SomeNewProperty = value
};
I guess this could be done with some reflection, but I imagine there is a faster approach which makes something equivalent to the first cumbersome approach.
Thanks, Lasse