Question about interfaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Pennington

    #1

    Question about interfaces

    Is there an easy way to find out what classes implement a given interface?
    For example, it might be useful to know what classes implement ICollectible.

    Much obliged,
    Geoff.


  • Imran Koradia

    #2
    Re: Question about interfaces

    If TypeOf myCollection Is ICollectible Then
    ' myCollection implements ICollectible
    End If

    If GetType(ICollec tible).IsAssign ableFrom(myColl ection.GetType) Then
    'again, myCollection implements ICollectible
    End If

    In C#, I believe you can use the typeof keyword to get the type of an
    object.

    Also, You can use the Type.GetInterfa ces method to get a collection of type
    objects for all the interfaces implemented by an object. You can also use
    the Type.GetInterfa ce method to get an interface by name.

    hope that helps..
    Imran.


    "Geoff Pennington" <GeoffPenn@veri zon.netNoSpam> wrote in message
    news:evJ9nyfsEH A.3152@TK2MSFTN GP14.phx.gbl...[color=blue]
    > Is there an easy way to find out what classes implement a given interface?
    > For example, it might be useful to know what classes implement[/color]
    ICollectible.[color=blue]
    >
    > Much obliged,
    > Geoff.
    >
    >[/color]


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Question about interfaces

      Geoff Pennington <GeoffPenn@veri zon.netNoSpam> wrote:[color=blue]
      > Is there an easy way to find out what classes implement a given interface?
      > For example, it might be useful to know what classes implement ICollectible.[/color]

      Again, MSDN is your friend. Go to the overview page for the interface,
      and it lists the classes which implement it directly.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Geoff Pennington

        #4
        Re: Question about interfaces

        If I understand correctly, you are answering the opposite question from the
        one I asked. Your reply seems to address the question "What interfaces does
        this class implement?", but what I want to know is "What classes implement
        this interface?".

        Sometimes, when choosing a class for a specific purpose, I want to be sure I
        have considered all the options.

        Geoff.

        "Imran Koradia" <nospam@microso ft.com> wrote in message
        news:ekPm45fsEH A.1216@TK2MSFTN GP10.phx.gbl...[color=blue]
        > If TypeOf myCollection Is ICollectible Then
        > ' myCollection implements ICollectible
        > End If
        >
        > If GetType(ICollec tible).IsAssign ableFrom(myColl ection.GetType) Then
        > 'again, myCollection implements ICollectible
        > End If
        >
        > In C#, I believe you can use the typeof keyword to get the type of an
        > object.
        >
        > Also, You can use the Type.GetInterfa ces method to get a collection of[/color]
        type[color=blue]
        > objects for all the interfaces implemented by an object. You can also use
        > the Type.GetInterfa ce method to get an interface by name.
        >
        > hope that helps..
        > Imran.
        >
        >
        > "Geoff Pennington" <GeoffPenn@veri zon.netNoSpam> wrote in message
        > news:evJ9nyfsEH A.3152@TK2MSFTN GP14.phx.gbl...[color=green]
        > > Is there an easy way to find out what classes implement a given[/color][/color]
        interface?[color=blue][color=green]
        > > For example, it might be useful to know what classes implement[/color]
        > ICollectible.[color=green]
        > >
        > > Much obliged,
        > > Geoff.
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Geoff Pennington

          #5
          Re: Question about interfaces

          OK, good. Thanks.

          "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
          news:MPG.1bd8a6 53a97f5e3398b6d 5@msnews.micros oft.com...[color=blue]
          > Geoff Pennington <GeoffPenn@veri zon.netNoSpam> wrote:[color=green]
          > > Is there an easy way to find out what classes implement a given[/color][/color]
          interface?[color=blue][color=green]
          > > For example, it might be useful to know what classes implement[/color][/color]
          ICollectible.[color=blue]
          >
          > Again, MSDN is your friend. Go to the overview page for the interface,
          > and it lists the classes which implement it directly.
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • Imran Koradia

            #6
            Re: Question about interfaces


            "Geoff Pennington" <GeoffPenn@veri zon.netNoSpam> wrote in message
            news:e6DvkAgsEH A.3984@TK2MSFTN GP09.phx.gbl...[color=blue]
            > If I understand correctly, you are answering the opposite question from[/color]
            the[color=blue]
            > one I asked. Your reply seems to address the question "What interfaces[/color]
            does[color=blue]
            > this class implement?", but what I want to know is "What classes implement
            > this interface?".[/color]

            My apologies. I misread your question. However, there's no way through code
            to figure out what classes implement a given interface. If you are talking
            about classes and interfaces in the .NET class library, you can look up the
            MSDN documentation for the given interface - it'll have a list of classes
            that directly implement the interface.

            hope that helps..
            Imran.


            Comment

            Working...