Monday, 12 August 2013

How to cast to an object to a type when type is known during runtime?

How to cast to an object to a type when type is known during runtime?

I have a statement something like this: MyClass myClass =
report.DataSource as MyClass
During runtime, the type of the DataSource is MyClass but it's in a
different namespace than the current running project. That's because two
projects are creating the same classes from the same service reference.
DataSource points to one namespace and the MyClass cast is from a
different namesapce. (it's complicated to explain how this occured)
During runtime, how do I use the type returned from
report.DataSource.GetType() (returns MyClass from another namespace) and
use it as type cast instead of 'MyClass' which is in the namespace which I
don't want?
(I hope I've explained it clearly. My brain is foggy now!)

No comments:

Post a Comment