get the Type for a object declared dynamic
I would like to get the Type for an dynamic object, something like:
dynamic tmp = Activator.CreateInstance(assembly, nmspace + "." + typeName);
Type unknown = tmp.GetType();
Except that in the above, GetType() returns the type of the wrapper for dynamic objects not the type of the wrapped object. Thanks!
Solution 1:
You need to do this...
Type unknown = ((ObjectHandle)tmp).Unwrap().GetType();
By the way, this is a little confusing because if you call Activator.CreateInstance on a type in your current assembly...
Activator.CreateInstance(typeof(Foo))
...the object is not wrapped and the original code works fine.
Solution 2:
If you can use Activator.CreateInstance, you can directly use:
object tmp = Activator.CreateInstance(assembly, nmspace + "." + typeName);
Type unknown = tmp.GetType();