Get an Interface of a Type

2

I want to see if a Type is implemented by the System.IDirectOutput interface and access its methods, but I do not know how, I'm trying this:

 If GetType(IDirectOutput).IsAssignableFrom(Expression) Then
      Return CType(Expression, IDirectOutput).InstanceOutput
 Else
      Throw New InvalidOperationException($"The specified type is not implemented from {NameOf(IDirectOutput)}.")
 End If

But it does not work :( Help me!

  

Update

I tried this method and it worked: ( in response to qmechanik )

 If TypeOf Expression Is IDirectOutput Then
     'statements...
 End If
    
asked by anonymous 18.06.2015 / 01:40

1 answer

2

The documentation for the Object.GetType suggests using TypeOf operator to check if an object matches a given < a

  • >
     If TypeOf Expression Is IDirectOutput Then
        Return CType(Expression, IDirectOutput).InstanceOutput
     Else
        Throw New InvalidOperationException($"The specified type is not implemented from {NameOf(IDirectOutput)}.")
     End If
    
        
  • 18.06.2015 / 03:20