Re: Runtime Determination of Interface Support

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

From: Richard Blewett [DevelopMentor] (richardb_at_develop.com)
Date: 09/16/04


To: microsoft.public.dotnet.languages.csharp
Date: Thu, 16 Sep 2004 00:37:34 -0700

One thing to remember with this approach is that the type check will be performed twice compared to the as operatorss once. Its much faster to compare a reference to null than to perform a type check.

 Regards

 Richard Blewett - DevelopMentor

 http://staff.develop.com/richardb/weblog

   nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/>

 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!
 
 
 
 ---
 Incoming mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004

 
 [microsoft.public.dotnet.languages.csharp]



Relevant Pages

  • 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: OO Factory
    ... has something called "interface", which is somewhat like N/E 4.0's "Interface", except that in Java, interfaces cannot have any code for their methods. ... I'm with you 100% where you were illustrating getting at different GUIs dependent upon which O/S you are referencing. ... Can Pete or Donald confirm whether Fujitsu supply you with the source programs for classes that are your support utilities, e.g. backup to their collection structure or the 'GUIs' in POWERFORM,? ...
    (comp.lang.cobol)
  • Re: Runtime Determination of Interface Support
    ... if (anObject is IDisposable) ... > will know the details of the interface, ... > documentation to find a clean way of doing this, ...
    (microsoft.public.dotnet.languages.csharp)