listing object members

ImDaFrEaK

Well-known member
Joined
Jan 7, 2006
Messages
416
Location
California
Programming Experience
5-10
Does anyone know a way to list the different areas of an object (properties/events/variables/sub routines/functions/ECT) for example the Visual Studio lists the properties of objects and their events ect... Can I do the same simply as if I wanted to make a minature IDE for myself?

I haven't reserched this any; just wanted to see if anyone had a quick solution or idea before I begin this quest.
 
A typical use of reflection! Type class is the root of the System.Reflection functionality and is the primary way to access metadata.
VB.NET:
Dim t As Type = GetType(TextBox)
Dim flags As BindingFlags = BindingFlags.Instance Or BindingFlags.Static Or BindingFlags.Public
Dim mis As MemberInfo() = t.GetMembers(flags)
 
Also perhaps relevant for you is the PropertyGrid control that lists the Designer properties of a class instance, allowing full runtime control of these same as in VB IDE. I found it in Toolbox > All Windows Forms listing, you set the SelectedObject to connect the instance.
 
Right on... I am very nieve to reflection, obviously, but that is really interesting. I have a good section on reflection in a VB book I own but I never really read it; just brushed through and didn't see anything I needed. Maybe I should have read it but I will most definately read it now. If you don't mind, and I am at work so I am unable to use my IDE to guess or piddle but how would you seperate properties from events and so on with the MemberInfo object you made? I also knew of the property grid control and thought I would get a response that mentioned it but I am glad you gave an alternate b/c that was the answer I wanted. Thanks again.


EDIT: Well, I have found a site at MS that helps me more in depth but I had to specifically look up reflection so thanks a ton. I will still find any further code samples or answers useful but I think you have me on the right track now to achieve this. Thanks again :)
 
Last edited:
The MemberType property of MemberInfo can tell you if the member is event, property... As mentioned the Type class is the 'root' and you should start by exploring the documentation for the members of this class, for example there exist also more specific methods like GetEvents, GetMethods and such. There are usually loads of code examples in documentation for every method/event/property etc. Also knowing specifically which method you want to apply makes it even easier to search up web tutorials and forum help.
 
Back
Top