Using reflection to get type members

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 ...
 
G

Guest

It will work if you use sClass = "System.Windows.Forms.CheckBox" instead.

HTH, Jakob.
 
M

MarkB

Thanks Jakob!

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

Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top