AJ.*_*AJ. 59
使用TypeOf ...是:
If TypeOf objectParameter Is ISpecifiedInterface Then
'do stuff
End If
Run Code Online (Sandbox Code Playgroud)
我还发现Scott Hansleman撰写的这篇文章对此特别有帮助.在他看来,他建议
C#
if (typeof(IWhateverable).IsAssignableFrom(myType)) { ... }
Run Code Online (Sandbox Code Playgroud)
我最终做了:
VB.Net
Dim _interfaceList As List(Of Type) = myInstance.GetType().GetInterfaces().ToList()
If _interfaceList.Contains(GetType(IMyInterface)) Then
'Do the stuff
End If
Run Code Online (Sandbox Code Playgroud)