471,627 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Reflection and Assemblies

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

Dec 8 '05 #1
2 1165
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.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<er************@cowaninsurancegroup.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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

Dec 8 '05 #2
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!!!

Dec 8 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Frazer | last post: by
4 posts views Thread by gary | last post: by
12 posts views Thread by Antony | last post: by
4 posts views Thread by Doug Handler | last post: by
6 posts views Thread by Cralis | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.