How do I use Refelection to get names and values of an object


Function GetWODataAsMessage(WO AsInteger) AsString


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”)


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


‘, prop.PropertyType ‘Testing only

msg = String.Concat(msg, vbCrLf, prop.Name, Tabs, prop.GetValue(result, Nothing))

End Select



Return msg

End Function

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: