1
在下面的代码,我想打电话,我在派生类中声明的方法:转换/投基类型派生泛型类型
class BaseClass
{
// ...
}
class A<T> : BaseClass
{
public void F(T args){ //... }
}
class B<T> : BaseClass
{
// B<T> doesn't have method F()
}
///....
class myApplication
{
// ...
public void DoSomething(BaseClass arg)
{
// Now I know that arg is of type A<T> for some type T
// but I don't know what T is. Also declaring DoSomething
// as DoSomething<T>() is not an option.
//
// I would like to call (arg as A<T>).F(...) but how can I
// deduce T? Can it be done in any other way?
}
}
请阅读代码中的注释。我该如何做这样的事情?
你试过'class myApplication'? –
假设你有你要传入F的对象,所以你不知道它的类型? –