By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,571 Members | 975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,571 IT Pros & Developers. It's quick & easy.

Check if Object implements an Interface?

P: n/a
Hi all,

I like to dynamically check if an object implements a particular interface.

Currently I am doing:

Ctype(Object, IInterface)

If the object implements the interface it will not throw an error... Is
there a better way I can do this via System.Reflection?

Thanks!

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Lucas Tam <RE********@rogers.com> wrote in
news:Xn***************************@127.0.0.1:
Hi all,

I like to dynamically check if an object implements a particular
interface.


Found the answer on groups.google.com : )

GetType.GetInterface()

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2

P: n/a
>If the object implements the interface it will not throw an error... Is
there a better way I can do this via System.Reflection?


Why do you want to use Reflection? The easiest way is

If TypeOf obj is IInterace Then

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #3

P: n/a
"Lucas Tam" <RE********@rogers.com> schrieb:
I like to dynamically check if an object implements a particular
interface.


Found the answer on groups.google.com : )

GetType.GetInterface()


I suggest to use 'TypeOf...Is' when possible.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4

P: n/a
Mattias Sjögren <ma********************@mvps.org> wrote in
news:ul**************@tk2msftngp13.phx.gbl:
Why do you want to use Reflection? The easiest way is

If TypeOf obj is IInterace Then


Oh Ha Ha... I didn't think TypeOf would check it's interfaces... I always
thought TypeOf only checked it's object type : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.