njsokalski
Well-known member
- Joined
- Mar 16, 2011
- Messages
- 102
- Programming Experience
- 5-10
I have a function that I am using to iterate and display the names & values of all the properties of an object. Here is my current code:
Private Function RequestFormValues(rf As NameValueCollection) As String
Dim type As Type = rf.GetType()
Dim properties() As System.Reflection.PropertyInfo = type.GetProperties()
Dim result As New StringBuilder()
For Each p As System.Reflection.PropertyInfo In properties
If IsNothing(p.GetValue(rf, Nothing)) Then
result.AppendFormat("{0}<br/>", p.Name)
Else
result.AppendFormat("{0}: {1}<br/>", p.Name, p.GetValue(rf, Nothing).ToString())
End If
Next
Return result.ToString()
End Function
However, the GetValue method is giving a Parameter Count Mismatch error. Most of the sites I have found say that this is because of parameterized properties and suggest using the GetIndexParameters method of PropertyInfo. However, I have been unable to get that to work. Can somebody tell me what I need to do to my code to fix it? Thanks.
Private Function RequestFormValues(rf As NameValueCollection) As String
Dim type As Type = rf.GetType()
Dim properties() As System.Reflection.PropertyInfo = type.GetProperties()
Dim result As New StringBuilder()
For Each p As System.Reflection.PropertyInfo In properties
If IsNothing(p.GetValue(rf, Nothing)) Then
result.AppendFormat("{0}<br/>", p.Name)
Else
result.AppendFormat("{0}: {1}<br/>", p.Name, p.GetValue(rf, Nothing).ToString())
End If
Next
Return result.ToString()
End Function
However, the GetValue method is giving a Parameter Count Mismatch error. Most of the sites I have found say that this is because of parameterized properties and suggest using the GetIndexParameters method of PropertyInfo. However, I have been unable to get that to work. Can somebody tell me what I need to do to my code to fix it? Thanks.