Why would you cast the thing to whatsthetype if you know you're going to treat it as an IBar ??
If it implements IBar, cast it to IBar and live a happy life. If you use IBar bar = foo as IBar; IQuux quux = foo as IQuux; you can find out what it implements by checking nullness. If you want to use a type (in this case interface IBar) in .Net, you either statically type your expression to be that type, or you go the reflection path. Even with reflection, if you don't know the type beforehand, how on earth are you going to make a program that's so intelligent that it figures out how to use the type on the fly ... -- Henkk ----- Original Message ----- From: "Steve Holak" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, June 06, 2002 12:18 AM Subject: [DOTNET] Casting to a Type from an Enum > I'm banging my head on something simple and don't have my references here: > > I have an object type returned by a function that has just de-serialized > that object from a database (Soap deserializer) . The object implements a > known interface (IBar). > > I know the type of the original object , but my knowledge of the type is > represented as a string. I want to cast the object to the Type defined by > the string, something like: > > > void CastTheDamnThing(string whatsthetype) > { > IBar MyVar; > > object foo=SomeFunctionThatReturnsAnObjectType(); > > //cast the object to the type defined by the string. > MyVar=(Type.GetType(whatsthetype)) foo; > > //do something else . . . > > } > > It obviously isn't right; > What am I missing? I feel dumb for asking, but it's the end of the day and > I'm not leaving until I figure out how to do this. > > TIA > > Steve Holak > Senior Software Architect > > Brokerage Concepts IS Dept. > 610-491-4879 > > email: [EMAIL PROTECTED] > > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.