I'm not sure why you need to cast to "whatsthetype", when you then assign it
to a variable of type IBar.  Why not this:

        IBar MyVar = (IBar) foo;

Seang

-----Original Message-----
From: Steve Holak [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 3:19 PM
To: [EMAIL PROTECTED]
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.

Reply via email to