473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 1215
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Frazer | last post by:
hi could any one tell me which real life senarios reflection can be used in ? thnx
4
by: gary | last post by:
Given an assembly loaded into memory, I can call GetTypes() to get a list of types that are defined in the assembly. However, how can I get a list of types that are used in the assembly that are...
4
by: Jimi | last post by:
Given a C# project file path, can I use reflection to get all the assemblies referenced by the project? e.g., I know the path of a C# project, say, "c:\SomeProject.csproj", and I want to load...
12
by: Antony | last post by:
Hello - I am wanting to print out a "Yes" next to classes that implement "Interface01", otherwise a "No". Here is my code. It crashes with a null reference exception and I am not sure why. Ideas?...
2
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to...
4
by: Doug Handler | last post by:
Ok, I think this is my last one - in my app, the user can select via a dialog box the dll's they want to load. I use a checkbox to track this (no worries there), but, once a dll has been bound,...
9
by: TS | last post by:
i have code that creates assemblies and classes from the assemlby and methods from the classes to set properties of dynamically created controls. How i should go about validating the assemblies,...
7
by: Allan Ebdrup | last post by:
How do I get hold of the type when I have a string that represents the type. For example I have the string "OFiR.Recruitment.Department" And I want to get the type called...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.