[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Checking for Interface and/or property

Rick Strahl

10/14/2002 12:20:00 AM

Is there a way to check whether an object exposes a given interface without
making a call to the interface and failing?

ALong the same lines is there a light weight way to check for the existance
of a property without walking through Reflection?

TIA,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwthreads/
-----------------------------------
Making waves on the Web with Visual FoxPro


2 Answers

Mattias Sjögren

10/14/2002 12:44:00 AM

0

Rick,

>Is there a way to check whether an object exposes a given interface without
>making a call to the interface and failing?

if ( obj is IFoo ) ...

If TypeOf obj Is IFoo Then ...


>ALong the same lines is there a light weight way to check for the existance
>of a property without walking through Reflection?

No, unless of course you make the property part of an interface.



Mattias

===
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.n...
Please reply only to the newsgroup.

Rick Strahl

10/14/2002 10:39:00 AM

0

Mattias

Aaaargh... Duh, how easy it is to miss the obvious. I'd been racking my head
trying to remember the 'is' keyword.

Thanks,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwthreads/
-----------------------------------
Making waves on the Web with Visual FoxPro

"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
news:e6mNLnwcCHA.2456@tkmsftngp08...
> Rick,
>
> >Is there a way to check whether an object exposes a given interface
without
> >making a call to the interface and failing?
>
> if ( obj is IFoo ) ...
>
> If TypeOf obj Is IFoo Then ...
>
>
> >ALong the same lines is there a light weight way to check for the
existance
> >of a property without walking through Reflection?
>
> No, unless of course you make the property part of an interface.
>
>
>
> Mattias
>
> ===
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.n...
> Please reply only to the newsgroup.