Re: Casting 'object' to "real/useful" Type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ignacio Machin ( .NET/ C# MVP )

    Re: Casting 'object' to "real/useful" Type

    Why can't we use Reflection to equip an application with the ability to cast
    an 'object' to it's "useful type" (e.g., MyDal) -- so that the application
    that is calling Activator.Creat eInstance can itself, at compile time, _not_
    know anything about the MyDal type (a class), and instead acquire that
    knowledge at runtime. Ideally, the application could somehow cast 'object'
    types to "real types" without having any compile-time knowledge of the "real
    type."
    >
    What am I missing?
    The difference between compile & runtime. CreateInstance works at
    runtime, you can pass ANY string to it (even an incorrect one like
    "1231231231 23") and it will compile
    Only at runtime you will get the error.
    And honestly, you HAVE to know something about your Class. otherwise,
    how do you know which method to call?
Working...