Henk (and all) I agree it sounded strange when I re-read it this morning; I didn't include enough information in the background for it to make sense. The casting to the interface and invoking that interface's functions wasn't the problem; there was more involved that required casting the object to its original type as well. I should have just left out any reference to an interface cast; it wasn't relevant.
For closure, a known object was serialized with the SoapSerializer and stored in a database for rehydration, along with an enum that indicated the original object's type, and a guid identifier. A program later would retrieve the object data, only having information about the guid, re-hydrate the object with a SOAP de-serializer; at that point the object's type was simply a system object. The next step is using the data about the object's original type to cast it to that type; I originally simply used a switch statement--which required type knowledge, obviously, but I wanted what I thought was a simpler, more flexible, and more elegant solution of using the stored type description to make the cast on the fly, something like varTypedObject=(Type.GetType(stringlabelingthetype)) varObject That was the sort of syntax I was looking for originally in the email. Thanks for taking a look, I appreciate your time (and everyone else's on the list). Sorry about the confusion, but it was at the end of a long day. Steve Holak Senior Software Architect Brokerage Concepts IS Dept. 610-491-4879 email: [EMAIL PROTECTED] Henk de Koning <[EMAIL PROTECTED] To: [EMAIL PROTECTED] OM> cc: Sent by: The Subject: Re: [DOTNET] Casting to a Type from an Enum DOTNET list will be retired 7/1/02 <[EMAIL PROTECTED] VELOP.COM> 06/05/2002 06:48 PM Please respond to The DOTNET list will be retired 7/1/02 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. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.