I have a GenericListItem object that has a Text and ID property. I am casting various DB objects into List for the purpose of binding to simple generic list controls.
I would like to write an extension method on List that would allow me to specify the relevant properties of T that would get mapped to the Text and ID properties of GenericListItem and then be able to easily convert any List to a list
The signature for the method would need to then somehow accept the two properties of T so I can then output from the list a new List
is something like this possible?
Instead of reinventing the wheel, you can use Linq:
If you really insist on extension, you can wrap the above logic into an extension method, but I don’t see the point:
Whatever you choose, don’t write a method where you specify properties by name. When you change the name of the properties, compiler will not be able to show you that you have forgotten to update the names in calls to your method, because they are just strings.