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.Form s,") 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 ... 2 1712
It will work if you use sClass = "System.Windows.Forms.CheckBox" instead.
HTH, Jakob.
-- http://www.dotninjas.dk
"MarkB" wrote: 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.Form s,") 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!
"Jakob Christensen" <jc*@REMOVEpension.dk> wrote in message
news:D0**********************************@microsof t.com... It will work if you use sClass = "System.Windows.Forms.CheckBox" instead.
HTH, Jakob. -- http://www.dotninjas.dk
"MarkB" wrote:
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.Form s,") 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 ... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Loesgen |
last post by:
The next San Diego .Net User Group meeting is Tuesday, November 25,
2003 at the Scripps Ranch Library.
Scripps Ranch Library
10301 Scripps Lake Drive
San Diego, CA 92131-1026
Please join us...
|
by: UJ |
last post by:
Can somebody point me to an explanation of what Reflection is? I've tried
looking in the help and it's not very helpful.
TIA - Jeff.
|
by: Robert W. |
last post by:
I've almost completed building a Model-View-Controller but have run into a
snag. When an event is fired on a form control I want to automatically
updated the "connnected" property in the Model. ...
|
by: Opa |
last post by:
Hi,
I'm trying to get some private class members using reflection, but am having
trouble: Example
using System;
using System.Reflection;
public class Customer
{
|
by: trevorelbourne |
last post by:
Hi,
I am having trouble accessing the elements of an array using
reflection. This is the code I am having trouble with:
FieldInfo Fields = Obj.GetType().GetFields();
foreach (FieldInfo fi in...
|
by: Ken Varn |
last post by:
I have an ASP.NET application that is calling a custom class that is trying
to parse all of the members of my Page object using Type.GetMembers(). The
problem that I am having is that private...
|
by: Don |
last post by:
How do I get an Enum's type using only the Enum name?
e.g.
Dim enumType as System.Type
Dim enumName as String = "MyEnum"
enumType = ???(enumName)
|
by: Mario Vázquez |
last post by:
Hi,
I have a component which exposes an extended property. I want to edit this
property using a UITypeEditor. The problem is that when the designer raises
my UITypeEditor sends a reference of...
|
by: prabhupr |
last post by:
Hi Folks
I was reading this article
(http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on
"Custom Attribute", written by Bipin.
The only thing I did not understand in this article...
|
by: chandramohanp |
last post by:
Hi
I am trying to modify class instance members using reflection. I am having problem when trying to add/remove/display elements related to List<int> member. Following is the code.
class...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
| |