Link to home
Start Free TrialLog in
Avatar of epaga
epaga

asked on

Reflection with unknown assembly?

Hi there!
I'm working with System.Reflection. So far it works nicely for dll's, like to invoke a static method:
                        
Assembly assembly = Assembly.LoadFrom(dllName);
System.Type type = assembly.getType(className);
MethodInfo method = type.GetMethod(mName,types);  // types are the types of parameters I'm using
Object myObj = method.Invoke(null,myParams);
...

What do I do though, if I want to call a method of a class not in that dll, but say, for example, in System.IO? That is, I'm calling this reflection method from a different program, and I can specify that I want to use method "getFiles()" in class "Directory" or even class "System.IO.Directory". But of course I don't specify the assembly to use.
Is there a way to do that? Hope my question is clear, if not, please ask...
Thanks!
epaga
Avatar of ptmcomp
ptmcomp
Flag of Switzerland image

It is definitely possible since there is a program called ".net Reflector" from Lutz Roeder which is doing it. But you must know where your class is located / what assemblies you need to load to create the class. You could of course load a set of assemblies by default but if the class is defined in a different assembly that particular assembly and its dependencies must be loaded.
Avatar of epaga
epaga

ASKER

so say I do know I need "System.IO"...how do I load that dynamically?

epaga
ASKER CERTIFIED SOLUTION
Avatar of ptmcomp
ptmcomp
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also load an assemlby and enumerate all the types that it defines.
Avatar of epaga

ASKER

That's exactly what I wanted to know!
Thanks ptmcomp...