Connecting Tech Pros Worldwide Forums | Help | Site Map

Tip: Propertyinfo.getValue in VB

SyZLaB
Guest
 
Posts: n/a
#1: Apr 21 '06
I had a problem using system.reflection.propertyinfo.getvalue in vb -
and searched a lots of newsgroups and libraries - but none had the
solution to my problem - and it also seamed like many others had the
same problem: system.reflection.propertyinfo.getValue fails with
"Object does not match target type."

As many of the posts where to old to answer, here's the "solution" :
The obj parameter is the object from where propertyinfo gets the
property from - not the property object it self..

To list all values of all properties of type system.string - ex:

Dim str as string ="" ' - some string to send the output to
Dim obj as someobject ' - a object with properties
Dim objProps() As System.Reflection.PropertyInfo =
GetType(obj).GetProperties

For Each p As System.Reflection.PropertyInfo In objProps
If p.PropertyType Is GetType(System.String) Then
str += p.Name.ToString & " = " & p.GetValue(obj,
Nothing).ToString
end if
next


Closed Thread


Similar Visual Basic .NET bytes