Reflection and Assemblies

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
 
N

Nicholas Paldino [.NET/C# MVP]

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

erin.sebastian

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!!!
 

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