Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I want to loop through an objects properties to return their values, but the objects passed to the sub could be of different types.

 

Isn't there a way that I loop through properties without actually knowing the properties, like:

 

public sub LoopPropse(obj)
If object.property.Count >= 1 Then
  For i = 1 to obj.property.count
     msgbox(object.property.item(1))
   Next
  end function
End If

 

Maybe a poor example but hopefully you understand what I mean..

 

Thanks,

LiQuiD8

Edited by liquid8
Posted

Actually, I realized as soon as I posted that this would involve Reflection... but if someone could post an example that would be extremely helpful..

 

Thanks again,

LiQuiD8

  • *Experts*
Posted

You can also use the PropertyGrid control (the same grid used to change design time properties) if you just want to view the properties (and make changes). This won't help you enumerate the properties yourself (use divil's code for that).

 

I've used it in a production app for some simple classes. Here's an article about it as well.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...