You need to do:
bool test = myType.IsInstanceOfType(obj);
or
bool test = myType.IsAssignableFrom(obj.GetType());
// var p = Convert.ChangeType(obj, myType); - update: this is not what the OP asked
For the second, you cannot "distinguish" an expression from a type that is unknown at compile time. The casting point must refer to members of this type initially. If you do not know that the type is in the compilation type (because you are using .GetType()), then there is no caste, and perhaps this is not possible.
source
share