我有以下接口和类
Public Interface IMyInterface
Sub GenericImplementation()
End Interface
Public Class MyClass
Implements IMyInterface
Public Sub GenericImplementation() implements IMyInterface.GenericImplementation
'doing some stuff
end Sub
Public Sub DoRefresh()
'doing some stuff
End Sub
End Class
现在我有一些代码,我想检查我作为接口传递的对象是否属于具体类型MyClass
,然后执行DoRefresh()
Public Sub TestMethod(testObject As IMyInterface)
Dim test = TryCast(testObject, MyClass)
If test IsNot Nothing Then
test.DoRefresh()
End If
End Sub
当我调试代码时,我可以清楚地看到我的接口实例是“MyClass”。但是当我 TryCast 时它什么也没返回。