I have classes that store data, and methods to go get data for individual loans.
I have code that walks properties and pulls the data back, but according to the MSDN coding guidelines properties are just supposed to get data, not do anything. My properties actually move to a screen on a mainframe and scrape data. So when I am mousing over a property or moving my mouse over the code in the debugger, sometimes it triggers, changes what screen in the mainframe I’m in. So I’d like to change my reflection walker to also be able to pull back function results and change the unbuffered data to functions.
Public Function GetAllReadableProperties(ByVal obj As Object) As String Dim result As New System.Text.StringBuilder(300) For Each Item As System.Reflection.PropertyInfo In obj.GetType.GetProperties() With Item If .CanRead Then result.Append(.Name + ':') If .GetIndexParameters().Length = 0 Then Dim value As Object = .GetValue(obj, Nothing) If value Is Nothing Then result.AppendLine('<Nothing>') Else result.AppendLine(value.ToString) End If Else result.AppendLine('Indexed') End If End If End With Next Return result.ToString End Function
How would I walk the methods also? What would the easiest way to tag certain functions for default walking, or default don’t walk? Custom attributes?
Would this code work at all for a structure passed in instead of a class?
I’d like to code this into building a datatable for datagridview display when I get farther along.
Re mousing over, perhaps
[DebuggerBrowsable(DebuggerBrowsableState.Never)]?However, perhaps a better approach is to follow the guidelines, and make the properties idempotent, with methods to populate them? i.e. call the ‘populate’ method (telling it what you need to know) before passing the object to the grid.
For a struct… well, a struct should (except for very specific reasons) always be immutable. So a lazy-loading struct is pretty much an oxymoron. You would probably run the risk of losing track of what is going on here… short version: make it a class (quite possibly one that is
IDisposable, and possibly has a finalizer).