GetAllMembers – Retrieving a hashtable containing all the members in a type

GetAllMembers – Retrieving a hashtable containing all the members in a type

' Return a case-insensitive hashtable containing all the members in a type' Note: requires Imports System.Reflection'' Example:'    Dim ht As Hashtable = GetAllMembers(GetType(String), False)'    For Each key As Object In ht.Keys'        Dim member As MemberInfo = DirectCast(ht(key), MemberInfo)'        Debug.WriteLine(key.ToString() & " - " & '           ' member.MemberType.ToString())'    NextFunction GetAllMembers(ByVal type As Type, ByVal includePrivate As Boolean) As _    Hashtable    Dim ht As Hashtable = _        Specialized.CollectionsUtil.CreateCaseInsensitiveHashtable()    ' decide which members should be retrieved    Dim flags As BindingFlags = BindingFlags.Instance Or BindingFlags.Static Or _        BindingFlags.Public    If includePrivate Then        flags = flags Or BindingFlags.NonPublic    End If    ' move members into the hashtable    For Each member As MemberInfo In type.GetMembers(flags)        ' avoid duplicates caused from member overloading        If Not ht.Contains(member.Name) Then            ' filter off special methods            If member.MemberType <> MemberTypes.Method OrElse CType(member, _                MethodInfo).IsSpecialName = False Then                ht.Add(member.Name, member)            End If        End If    Next    Return htEnd Function

See also  11 Effective Keyword Research Tools and Techniques

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist