M
mark
hi, I get the problem here, I have exception thrown when I try to cast
the reflection created object.
first there is BaseObject dll that implemation a interface, factory
dll use the reflection load the dll, create the object and return.
BaseObject reference the factory dll.
factory.dll
public object CreateObj(string objectType, ref string suppMsg)
{
string LoadObj = string.Format("WitsmlObjects.{0}",objectType);
witsObject = WitsmlObjectsDll.CreateInstance(LoadObj);
}
test code:
Factory fac = new Factory();
object s = fac.CreateObj("baseObject",ref suppMsg);
// if check the type both are not equal.
if(s.GetType()== typeof(baseObject)
{
.....
}
// this fail, but would be ok to
(Object)fac.CreateObj(strObj,ref suppMsg). if cast objec ot baseobject
fail.
obj = (BaseObject)fac.CreateObj(strObj,ref suppMsg);
the reflection created object.
first there is BaseObject dll that implemation a interface, factory
dll use the reflection load the dll, create the object and return.
BaseObject reference the factory dll.
factory.dll
public object CreateObj(string objectType, ref string suppMsg)
{
string LoadObj = string.Format("WitsmlObjects.{0}",objectType);
witsObject = WitsmlObjectsDll.CreateInstance(LoadObj);
}
test code:
Factory fac = new Factory();
object s = fac.CreateObj("baseObject",ref suppMsg);
// if check the type both are not equal.
if(s.GetType()== typeof(baseObject)
{
.....
}
// this fail, but would be ok to
(Object)fac.CreateObj(strObj,ref suppMsg). if cast objec ot baseobject
fail.
obj = (BaseObject)fac.CreateObj(strObj,ref suppMsg);