Test if an object implements an interface
Solution 1:
Use TypeOf...Is:
If TypeOf objectParameter Is ISpecifiedInterface Then
'do stuff
End If
Solution 2:
I also found this article by Scott Hansleman to be particularly helpful with this. In it, he recommends
C#
if (typeof(IWhateverable).IsAssignableFrom(myType)) { ... }
I ended up doing:
VB.Net
Dim _interfaceList As List(Of Type) = myInstance.GetType().GetInterfaces().ToList()
If _interfaceList.Contains(GetType(IMyInterface)) Then
'Do the stuff
End If
Solution 3:
requiredInterface.IsAssignableFrom(representedType)
both requiredInterface and representedType are Types
Solution 4:
Here is a simple way to determine whether a given object variable "o" implements a specific interface "ISomething":
If o.GetType().GetInterfaces().Contains(GetType(ISomething)) Then
' The interface is implemented
End If