I am trying to write a generic function that generates an Xelement based on a list of objects, and a property of the object
Currently I have this code copied and pasted in several spots
InputElementsArray = New XElement(New XElement("ArrayInputs", _
New XElement("InputName", "TestFailedRefDesList"), _
New XElement("DataType", "StringArray"), _
New XElement("ValueList", From d In _PassFailItem.FailureDetails Select New XElement("InputValue", d.RefDes))))
InputElements.Add(InputElementsArray)
The above code works fine for me, but I would much rather create one single function that does the same task given an object and a property
Private Shared Function CreateBaseArrayInputs(Of T)(ByVal ListOfItems As List(Of T)) As XElement
Dim InputElementsArray As XElement = _
New XElement("ArrayInputs", _
New XElement("InputName", "TestFailureCodeList"), _
New XElement("DataType", "StringArray"), _
New XElement("ValueList", From d In ListOfItems Select New XElement("InputValue", d)))
Return InputElementsArray
End Function
I am unsure about how I can generically set the property of d to use. Any ideas?