G
Guest
Hello,
Is there a way to cast to another type when all we have is the System.Type.
Say, if we have:
Class MyBaseClass;
Class MyDerivedClass:MyBaseClass;
instead of:
MyDerivedClass derivedObject = new MyDerivedClass();
MyBaseClass baseObject = (MyBaseClass) derivedObject;
something like this:
public object CastToBaseClass( object someObject )
{
System.Type baseType = someObject.GetType().BaseType;
//now what? :S
object baseObject = (/* what goes here?*/) someObject;
//in my dreams: ... keyword "classof", inverse of "typeof"
// object baseObject = (classof( baseType ) ) someObject;
}
Anything like that in the framework?
Thanks
Is there a way to cast to another type when all we have is the System.Type.
Say, if we have:
Class MyBaseClass;
Class MyDerivedClass:MyBaseClass;
instead of:
MyDerivedClass derivedObject = new MyDerivedClass();
MyBaseClass baseObject = (MyBaseClass) derivedObject;
something like this:
public object CastToBaseClass( object someObject )
{
System.Type baseType = someObject.GetType().BaseType;
//now what? :S
object baseObject = (/* what goes here?*/) someObject;
//in my dreams: ... keyword "classof", inverse of "typeof"
// object baseObject = (classof( baseType ) ) someObject;
}
Anything like that in the framework?
Thanks