If you want log something it can be usefull to print out the properties of a object. When you define a object yourself the code below can be usefull.
This function prints out each property of the object
Public Overrides Function toString() As String
'create Stringbuilder
Dim sbReturn As StringBuilder = New StringBuilder(Me.GetType().Name) sbReturn.Append(" :")
For Each PropertyItem As PropertyInfo In Me.GetType().GetProperties()
'add data
sbReturn.Append(PropertyItem.Name)
sbReturn.Append("= ")
sbReturn.Append(PropertyItem.GetValue(Me, Nothing).ToString())
sbReturn.Append(", ")
Next
'return
Return Trim(sbReturn.ToString())
End Function
Make sure u import System.Reflection
Imports System.Reflection
Reacties
William schreef:
05/02/07
Is there anyway to modify the property looping function to loop through child objects? Currently gives a "object not initiated" error.
tijs schreef:
05/02/07
Feel free to modify it. I 'll have a look at it, but I'm really busy.