How do I use Refelection to get names and values of an object
15-Aug-1212 Leave a comment
Function GetWODataAsMessage(WO AsInteger) AsString
‘#1446
SetContext()
Dim result = (From w In context.WorkOrders Where w.WO = WO Select w).FirstOrDefault
If result IsNothing Then
Return String.Concat(“WO, “, WO, ” was not found”)
EndIf
Dim msg = String.Concat(“Information for W-“, WO)
ForEach prop In result.GetType().GetProperties
If prop.CanRead Then
SelectCase prop.PropertyType
CaseGetType(Byte()), GetType(Business.EBC.EntityModel.Product)
‘Do Nothing
‘Case GetType(Business.EBC.EntityModel.Product)
‘ ‘Do Nothing
Case Else
Dim Tabs = String.Concat(vbTab, vbTab)
If prop.Name.Length < 4 Then
Tabs = String.Concat(vbTab, vbTab, vbTab)
ElseIf prop.Name.Length > 16 Then
Tabs = vbTab
EndIf
‘, prop.PropertyType ‘Testing only
msg = String.Concat(msg, vbCrLf, prop.Name, Tabs, prop.GetValue(result, Nothing))
End Select
EndIf
Next
Return msg
End Function