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

 

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

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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: