Using reflection to get type members

  • Thread starter Thread starter MarkB
  • Start date Start date
M

MarkB

I am new to using reflection, and I can't understand why this code fails for
sClass="CheckBox"

'get loaded assemblies
oAssemblies = AppDomain.CurrentDomain.GetAssemblies()

'find our type in one of the assemblies
For Each oAssembly In oAssemblies

oType = oAssembly.GetType(sClass, False, True)

If Not (oType Is Nothing) Then

MsgBox("Got type '" & sClass & "' in assembly '" & oAssembly.FullName &
"'")
cRet.Add(oAssembly.FullName)
cRet.Add(sClass)
oMethInfo = oType.GetMethods(iFlags)

For Each oMI In oMethInfo
cRet.Add(" Method: " & oMI.Name() & " (" & oMI.ToString & ")")
oParamInfo = oMI.GetParameters()

For Each oPI In oParamInfo
cRet.Add(" param: " & oPI.Name() & " As " & oPI.GetType.Name)
Next 'oPI

Next 'oMI

End If ' Not (oType Is Nothing)

Next 'Assembly

That is, the CheckBox type is not found in any loaded assembly. BUT this
code, which iterates over the types in the System.Windows.Forms assembly
DOES work!

'get loaded assemblies
oAssemblies = AppDomain.CurrentDomain.GetAssemblies()

'find our type in the System.Windows.Forms assembly
For Each oAssembly In oAssemblies

'look only in the System.Windows.Forms assembly
If oAssembly.FullName.StartsWith("System.Windows.Forms,") Then

'iterate over all WinForms types
oTypes = oAssembly.GetTypes()

For Each oType In oTypes

If StrComp(oType.Name, sClass, CompareMethod.Text) = 0 Then
cRet.Add(oAssembly.FullName)
cRet.Add(sClass)

oMethInfo = oType.GetMethods(iFlags)
For Each oMI In oMethInfo
cRet.Add(" Method: " & oMI.Name() & " (" & oMI.ToString & ")")
oParamInfo = oMI.GetParameters()

For Each oPI In oParamInfo
cRet.Add(" param: " & oPI.Name() & " As " & oPI.GetType.Name)
Next 'oPI

Next 'oMI

End If 'is our type (sClass)

Next 'oType
End If 'is WinForms
Next 'assembly

Anyone have a clue as to what I'm doing wrong?? Thanks ...
 
Thanks Jakob!

Although I wonder why a fully qualified name is required ... I have a lot
more experimentation to do!

Cheers!
 
Back
Top