tags:

views:

125

answers:

2

I have an object parameter and I need to check if the object implements a specified interface in vb.net. How to test this?

Thanks.

+7  A: 

Use TypeOf...Is:

If TypeOf objectParameter Is ISpecifiedInterface Then
    'do stuff
End If
AJ
Note that if "do stuff" requires invoking a member of the interface on the object, you probably want to use 'As' to cast and then ensure object 'IsNot Nothing'. (This prevents an unnecessary second cast.)
bobbymcr
+2  A: 

requiredInterface.IsAssignableFrom(representedType)

both requiredInterface and representedType are Types

Joe Caffeine