How identify object by Interface type

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

    #1

    How identify object by Interface type

    I'm writing a .net3.0 WPF app in c# and want to determin if an object
    implements a certain interface something like this:

    UIElement elem = GetObjectClicke d(e.source as DependancyObjec t)

    if(elem.type==I Selectable)
    {
    return elem;
    }

    Where ISelectable is the interface I'm looking for. In otherwords, how do I
    determin if 'elem' implements ISelectable?

    Thanks



    --
    moondaddy@noema il.noemail


  • Jon Skeet [C# MVP]

    #2
    Re: How identify object by Interface type

    moondaddy <moondaddy@noem ail.noemailwrot e:
    I'm writing a .net3.0 WPF app in c# and want to determin if an object
    implements a certain interface something like this:
    >
    UIElement elem = GetObjectClicke d(e.source as DependancyObjec t)
    >
    if(elem.type==I Selectable)
    {
    return elem;
    }
    >
    Where ISelectable is the interface I'm looking for. In otherwords, how do I
    determin if 'elem' implements ISelectable?
    if (elem is ISelectable)

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • Keith Patrick

      #3
      Re: How identify object by Interface type

      You can also use Type.IsAssignab leFrom (if you have the type but not the
      object ref)



      Comment

      • moondaddy

        #4
        Re: How identify object by Interface type

        Thanks Jon,

        That was too easy!

        "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
        news:MPG.204d56 94ea78073a98d8d 4@msnews.micros oft.com...
        moondaddy <moondaddy@noem ail.noemailwrot e:
        >I'm writing a .net3.0 WPF app in c# and want to determin if an object
        >implements a certain interface something like this:
        >>
        >UIElement elem = GetObjectClicke d(e.source as DependancyObjec t)
        >>
        >if(elem.type== ISelectable)
        >{
        > return elem;
        >}
        >>
        >Where ISelectable is the interface I'm looking for. In otherwords, how
        >do I
        >determin if 'elem' implements ISelectable?
        >
        if (elem is ISelectable)
        >
        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        Working...