Question Parameter Count Mismatch when Iterating Properties

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.
 
In don't see the point in you reflecting the NameValueCollection type, wouldn't this be the result you're after:
        For Each key As String In rf.Keys
            result.AppendFormat("{0}: {1}<br/>", key, rf(key))
        Next
 
In don't see the point in you reflecting the NameValueCollection type, wouldn't this be the result you're after:
        For Each key As String In rf.Keys
            result.AppendFormat("{0}: {1}<br/>", key, rf(key))
        Next

That's a good point, I guess it just slipped my mind when I wrote this. Thanks for pointing it out.
 
Back
Top