I have a class
class Bar<T>:Foo
{
// implements Foo's method
public Type typeOfGeneric
{
get
{
return T.class;
}
}
}
and in somewhere else, I need to do this:
var test = tmp as Foo;
var baseObject = (Bar<tmp.typeOfGeneric>)tmp;
I know this looks weird but I just wonder if it is possible to cast something to a generic T while not knowing T in run-time and get that T in run-time.
Foo doesn't have type T, Bar has type, I need Foo to return Bar type T to be able to use its own methods.
For example, I can't add this in Foo
Bar<T> getCastType{get;}
because T is not know to Foo interface.