Re: Runtime Determination of Interface Support

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 09/15/04


Date: Wed, 15 Sep 2004 11:20:43 -0500

Pete,
In addition to the other comments (the as operator).

You can also use the is operator.

    object anObject;
    if (anObject is IDisposable)
    {
        IDisposable disposable = (IDisposable)anObject;
        // do something with disposable
    }

Hope this helps
Jay

"Pete" <anonymous@devdex.com> wrote in message
news:OA9lrvzmEHA.1716@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> Is it possible for an application to determine, at runtime, whether an
> arbitrary class supports a known interface?
>
> I can think of a couple of cludgy ways of doing this (the calling app
> will know the details of the interface, so worst-case could just blindly
> try invoking a method) but I'm scanning through the reflection
> documentation to find a clean way of doing this, and haven't found
> anything thus far.
>
> Thanks,
> Pete
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: CLOS Properties Question
    ... >>have a working mind of my own, and I do happen to believe that a clean ... > wish to do with your libraries. ... > are writing client code to that interface. ...
    (comp.lang.lisp)
  • Re: [PATCH] cleanup ptrace stops and remove notify_parent
    ... > Should we also clean up and improve those with user-visible change? ... separate subject from the implementation changes we are discussing right ... I don't really want to get into discussing a different interface at ... An important step to a sane and clean implementation of whatever new ...
    (Linux-Kernel)
  • Re: Best Tool for automatic documentation generation?
    ... Pete. ... I really like your interface and I would be the happiest ... Danijel Tkalcec ... RealThinClient components ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Problem opening 16 bit application
    ... Assuming that you are using WinXP, and that you are not behind a corporate ... "Pete" wrote in message ... > but what is the alternative to the web based interface. ... >>>>Did you follow the advice Carey Frisch gave you at ...
    (microsoft.public.windowsxp.general)
  • Re: Dispose, Dispose(true), Finalize, IDisposable
    ... the Destructor such as ... There is no extra code executed when an object goes out of scope, as there is in a system using reference counting, so there is no way that you can make anything happen when an object goes out of scope. ... There is nothing magic about the IDisposable interface, it's just an interface as any other. ... system should still have the responsibility to clean up. ...
    (microsoft.public.dotnet.general)