Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reflection problem

Status
Not open for further replies.

zeevgetner

Programmer
Dec 24, 2000
37
IL
how can i do casting using reflection.
for examlple if i have a class in a DLL
i want in another aplication to load that class,
and assign it to a variable of type that the specific class
implements.

i cant do it,
i keep getting error.
 
could you post some code?

casting you do like this (OTTOMY unchecked):

Code:
ClassName instance = OtherClass.GetType().CreateInstance("ClassName") as ClassName;
if ( instance == null ) throw new Exception();

mr s. <;)

 
thank misterstick for your help
i found out what the problem was.

both the called class and the caller had reffrences to a base class.

i did kind of what you wrote but, i placed the called class in a diffrent librery from the caller.

so then when i called the class from the caller. the .net framework threated thir reffrences as diffrent even thow it were the same classes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top