S
smith
How can i convert an interface object back to it's
original object, without knowing original class name....
interface ITest
{
int some_method();
}
public class Test : ITest
{
int some_method()
{
return 0;
}
int some_newMethod()
{
return 1;
}
}
public class Test2 : ITest
{
int some_method()
{
return 0;
}
int some_newMethod()
{
return 1;
}
}
int test()
{
ITest t = new Test2();
return passtest(t);
}
int passtest(ITest ctest)
{
Assembly a = Assembly.GetExecutingAssembly();
// create a 'Test2' class, with out knowing
// original class name...
Object o = a.CreateInstance( ctest.GetType().ToString
(), ...);
return o.some_newMethod();
}
Is this correct... or is there some other more efficient
method or other way to do this?
Thanks
original object, without knowing original class name....
interface ITest
{
int some_method();
}
public class Test : ITest
{
int some_method()
{
return 0;
}
int some_newMethod()
{
return 1;
}
}
public class Test2 : ITest
{
int some_method()
{
return 0;
}
int some_newMethod()
{
return 1;
}
}
int test()
{
ITest t = new Test2();
return passtest(t);
}
int passtest(ITest ctest)
{
Assembly a = Assembly.GetExecutingAssembly();
// create a 'Test2' class, with out knowing
// original class name...
Object o = a.CreateInstance( ctest.GetType().ToString
(), ...);
return o.some_newMethod();
}
Is this correct... or is there some other more efficient
method or other way to do this?
Thanks