Reflection and Assemblies

  • Thread starter Thread starter erin.sebastian
  • Start date Start date
E

erin.sebastian

Hi All,
I am new to reflection and have successfully used it in a project, the
following code works wonderfully

ObjectHandle objectHandle = Activator.CreateInstance(this.AssemblyName,
this.ClassName);

// use the Activator to create an Instance
AbstractWebProperties webProperties = (AbstractWebProperties)
objectHandle.Unwrap();

Currently the user provides the assembly and the class name but i
don't want them to have to provide the assembly name, i would like to
be able to get the assembly name somehow from the class name that i
have stored in a string. Is there any way to do this???

Thanks,
Erin
 
Erin,

No, there really isn't. I could give you a class name in two separate
assemblies with the same namespace, same class name, and they would be
different types.

There is no way to get the assembly name from the class name. You can
search in loaded assemblies for that class name, but if you don't have
namespace information to go along with that, there is no way you can be sure
it is the class you want.

Hope this helps.
 
Ok another question then.

the assembly that i want is part of my solution it's just not the
currently executing assembly, so how i would search for the class
within the loaded assemblies and find the assembly that i want so that
i can plug it into this line

ObjectHandle objectHandle = Activator.CreateInstance(this.AssemblyName,
this.ClassName);

???
thanks again!!!
 
Back
Top