liquid8 Posted July 18, 2003 Posted July 18, 2003 (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 July 18, 2003 by liquid8 Quote
liquid8 Posted July 18, 2003 Author Posted July 18, 2003 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 Quote
*Gurus* divil Posted July 18, 2003 *Gurus* Posted July 18, 2003 Use TypeDescriptor.GetProperties, and go from there. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted July 18, 2003 *Experts* Posted July 18, 2003 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 Quote "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
liquid8 Posted July 21, 2003 Author Posted July 21, 2003 Thanks for both of your suggestions.. both will come in handy.. LiQuiD8 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.