Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB7
Expertise: Intermediate
Jan 5, 2004



Application Security Testing: An Integral Part of DevOps

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())
'    Next

Function GetAllMembers(ByVal type As Type, ByVal includePrivate As Boolean) As _
    Dim ht As Hashtable = _
    ' decide which members should be retrieved
    Dim flags As BindingFlags = BindingFlags.Instance Or BindingFlags.Static Or _
    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
    Return ht
End Function
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date