Hi Everyone,
I want to create an instance of a dynamic class in run time. The type of the
dynamic class is unknown during the compile time. I can use
Activator.CreateInstance to instantiate the dynamic class. But it returns
object data type. How can I get the instansce of the dynamic class as its own
data type?
Thanks in advance!!!
Cindy
Mattias Sj?gren - 01 Oct 2004 22:07 GMT
Cindy,
>How can I get the instansce of the dynamic class as its own data type?
Since the type is unknown at compile time, you can't declare a
variable of that type. So there's no point in such a cast.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
tom wisnowski - 05 Oct 2004 06:19 GMT
Can you be a little clearer on what you mean by dynamic class?
If you mean that you are dynamically "loading" a class, using its type name,
you can do a cast from object to type by either:
typedvar = (type)objvar
typedvar = objvar as type
But since you are dynimally loading the type, you must be in a situation
where the type is not available to you during compilation. In this case, you
will either have to use runtime reflection to access your members or bind to
a common interface
If you are dynamically generating the type, and then dynamically loading it,
you must use reflection or a predefined interface to access the type's members
Hope this helps
Tom Wisnowski
Statera
MCP MCAD
> Hi Everyone,
>
[quoted text clipped - 6 lines]
> Thanks in advance!!!
> Cindy
cindy liu - 05 Oct 2004 20:07 GMT
Thanks everyone! I found out I don't need to cast it at all.
Cindy
> Hi Everyone,
>
[quoted text clipped - 6 lines]
> Thanks in advance!!!
> Cindy