+92 332 4229 857 99ProjectIdeas@Gmail.com

All Classes Viewer (Vb.net)



The following code shows you all the classes of vb.net and list them in combobox... when the user choose any class from combobox then that class methods are displayed in listbox and if that class have any interface implements it shows in interface listbox. It is implemented using reflection technique. 
GETALLCLASSES(): this method loads all the classes from mscorlib.dll file to combobox.



Sub GetAllClasses()

     Dim asm As Assembly
     asm = Assembly.Load("mscorlib.dll")

        For Each t As Type In asm.GetTypes()
            cmboxAllClasses.Items.Add(t.ToString())
        Next

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        GetAllClasses()

End Sub

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        
  listBoxMethods.Items.Clear()
  listBoxInterfaces.Items.Clear()

  'Getting class name what user select from combobox
   Dim getClassName = cmboxAllClasses.SelectedItem.ToString()

  'Loading selected class, methodInfo from combobox.
   Dim methodInfo() As MethodInfo = Type.GetType(getClassName).GetMethods()

  'Loading selected class, interface from combobox.
   Dim interfaceInfo() As MemberInfo = Type.GetType(getClassName).GetInterfaces()

   Dim str As String = Nothing

  'Adding all methods to listbox plus their parameters also
   For Each method As MethodInfo In methodInfo
     
     Dim paramInfo() As ParameterInfo = method.GetParameters()
   
      For i As Integer = 0 To paramInfo.Length - 1

       str = "(" & paramInfo(i).ParameterType.Name & " " & paramInfo(i).Name & ")"

      Next

      listBoxMethods.Items.Add(method.Name & " " & str)
  Next

     For Each inter As MemberInfo In interfaceInfo

            listBoxInterfaces.Items.Add(inter.Name)

     Next

End Sub






0 comments: