Re: Runtime Determination of Interface Support
From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 09/15/04
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Cannot access a disposed object named "System.Net.TlsStream"."
- Previous message: Tom Porterfield: "Re: Casting and interface question"
- In reply to: Pete: "Runtime Determination of Interface Support"
- Next in thread: Pete: "Re: Runtime Determination of Interface Support"
- Reply: Pete: "Re: Runtime Determination of Interface Support"
- Reply: Richard Blewett [DevelopMentor]: "Re: Runtime Determination of Interface Support"
- Messages sorted by: [ date ] [ thread ]
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!
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Cannot access a disposed object named "System.Net.TlsStream"."
- Previous message: Tom Porterfield: "Re: Casting and interface question"
- In reply to: Pete: "Runtime Determination of Interface Support"
- Next in thread: Pete: "Re: Runtime Determination of Interface Support"
- Reply: Pete: "Re: Runtime Determination of Interface Support"
- Reply: Richard Blewett [DevelopMentor]: "Re: Runtime Determination of Interface Support"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|