Runtime Iteration of an Object's Members RRS feed

  • Question

  • Hi all;

    I'm looking to be able to iterate through all the members of a class, or an object thereof.  For example, if I could perform the following (using pseudo code):

    Private Structure MemberInfoType
        Dim Name As String    
        Dim ItsType As Type    
        Dim ItsValue As Object
    End Struct
    Dim membersInfo As New Collection(Of MemberInfoType)
    For Each member As Object In System.Diagnostics.Process      
        Dim memInfo As New MemberInfoType     
        With memInfo          
           .Name = member.Name          
           .ItsType = member.GetType          
           .ItsValue = member.Value     
        End With     
    Is this possible?  Thanks much to all!
    Glenn T. Kitchen

    Glenn T. Kitchen VB.NET Forums

    Monday, November 26, 2018 9:54 PM

All replies

  • Hello,

    I was just involved in a similar request which may be helpful. Besides looking at the code, read the comments where there are parts to get public and non-public methods and also to get properties. I did nothing here with delegates.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, November 26, 2018 10:07 PM
  • Thanks Karen!

    After looking in Object Browser at the System.Reflection Namespace I see that the same exists for Properties, i.e. PropertyInfo, which inherits MethodInfo.

    The System.Reflection Namespace appears to provide the functionalities I've been seeking and need to investigate further for the work I'm doing.  Thank you much for helping me with this!  

    Have Happy Holidays!

    Glenn T. Kitchen VB.NET Forums

    • Edited by αβθ-Coder Tuesday, December 4, 2018 11:41 PM spelling, phrasing
    Tuesday, December 4, 2018 11:37 PM