Help with c# reflection?
Posted on 2014-02-15
I am trying to write a WPF custom control, and am trying to refactor it so that any List<T> can be converted into a List<CustomType>.
The CustomType has an Id property that I want to be assigned with the value of the Id property from an instance of the source T.
But my problem is how to map the name of the Id property on the source to the Id property on the CustomType.
A pseudocode method follows:
private void UsePropertiesOfInputCollectionInCollectionOfAnotherClass(IEnumerable<object> inputCollection , string nameOfTheMemberThatHoldsTheIdValueOfAnInputObject, Type typeOfTheObjectsInTheCollection)
foreach (var inputObject in inputCollection)
//cast the input object to the typeOfTheObjectsInTheCollection
//interogate the member on the (cast)inputObject that is named: nameOfTheMemberThatHoldsTheIdValueOfAnInputObject
//Create a new instance of the AnotherClass
//assign the value of the interogated member to a property called AnotherClass.ClassID
Can you help?