Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test for system data types

Status
Not open for further replies.

ispeaker

Programmer
Dec 29, 2005
15
US
I am looping through all the properties of a class. Most are of a system data type (i.e. system.double, system.integer, etc.). Some are actually other classes. How can I tell at run time if the current property is a system data type or class or a collection?
 
Try this:
Code:
Dim obj As New <someclass>
        ''show all properties and their value in a class
        Dim prop As System.Reflection.PropertyInfo
        For Each prop In obj.GetType.GetProperties
            Response.Write(prop.Name + "<br>")
            Response.Write(prop.GetValue(obj, Nothing) + "<br>")
            Response.Write(prop.MemberType.ToString + "<BR>")

        Next prop
 
That got me one step close.
Debug.WriteLine(prop.MemberType.ToString()) always returns "Property." What I need to know is if the data type of the property is a system type (system.integer, system.double, etc.) or is it a class or collection.
 
It worked for me when I tested it.... there must be something in your class that is throwing it off. Use the response.write.. maybe the debug.writeline statment is causeing problems?
 
Yes, I got it to work using prop.PropertyType.ToString.
To make sure I read only properties with printable values, I used, If NOT prop.PropertyType.isClass then . . .
 
Hey.. glad you got it working. I didn't even see the propertyType. Glad you posted it. Thanks. I learned something new today..

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top