how to test if an object supports a given interface at runtime

M

MrB

Hi,
I'm writing an asp.net app in vb.net and many of my ascx classes support an
interface IAutoSave, but some do not.
I want to test in my code if the class behind a given ascx control supports
this interface. Currently I'm trapping for an error on converting the class
to this interface but am wondering if there is a more direct way of testing
if an object supports a given interface.
How do I do this?
Thanks in advance,
Jim
 
G

Guest

You can do the following:

IAutoSave autoSave = someObject as IAutoSave;
if(autoSave != null)
{
...
}

HTH

nick robinson
site : www.fromconcept.co.uk
blog : www.fromconcept.co.uk/weblog.aspx

----- MrB wrote: -----

Hi,
I'm writing an asp.net app in vb.net and many of my ascx classes support an
interface IAutoSave, but some do not.
I want to test in my code if the class behind a given ascx control supports
this interface. Currently I'm trapping for an error on converting the class
to this interface but am wondering if there is a more direct way of testing
if an object supports a given interface.
How do I do this?
Thanks in advance,
Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top