How weknows the implemented Interface name at run time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ashish Gupra
    New Member
    • Jun 2008
    • 14

    How weknows the implemented Interface name at run time

    Hi,

    Is there any method to know the interface name through which the class has been implemented?

    Example:

    Public Interface I1
    Public funcation Test() as string
    End Interface

    Public Class C1
    Implements I1

    Public function Test()as string implements I1.Test
    msgbox("Hello")
    End Function
    End Class

    Public Class C2
    Public function Test1(classobj as Object)
    ' Code to know about the implemented interface name of class C1
    ' I used following code, but it was not working.
    If classobj.getTyp e is GetType(I1) then
    ' Some code
    End If
    End Function
    End Class

    Regards,
    Ashish
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    Code:
    Dim oType As Type = MyObject.GetType()
    Dim oInterfaces As Type() = oType.GetInterfaces()
    For Each oInterface As Type In oInterfaces
        Console.WriteLine(oInterface.ToString())
    Next

    Comment

    • Ashish Gupra
      New Member
      • Jun 2008
      • 14

      #3
      Thanks,

      This will works...

      -- Ashish

      Comment

      Working...