473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
Nov 18 '05 #1
2 1616
I think you should take a look at System.Type.IsSubclassOf

Jerry

"MrB" <no**************@comcast.net> wrote in message
news:O9**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2
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

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kenneth Baltrinic | last post by:
I am getting the following error when deserializing an object that has a couple of dozen dependant objects in its object graph. Anyone who can suggest where I might begin to look to resolve problem...
30
by: jimjim | last post by:
Hello, This is a simple question for you all, I guess . int main(){ double *g= new double; *g = 9; delete g; cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl; *g =...
9
by: wildernesscat | last post by:
Hello there, I'm looking for a method to test, whether an object has a certain property. Consider the following snippet: class A { var $aaa; } $var = new A; (Assuming that the structure...
4
by: Technics | last post by:
Ok I will be as clearer as I can (sorry for english/technical mistakes) I would like to write an audio application that supports ASIO drivers. I downloaded the ASIO sdk from Stainberg and I read...
1
by: Anthony Paul | last post by:
Hello everyone! Let's say that I would like a generic type that supports Min/Max properties and can be double or integer or even datetime if need be, something flexible. So I go about...
15
by: Anthony Paul | last post by:
Let's say that I would like a generic type that supports Min/Max properties and can be double or integer or even datetime if need be, something flexible. So I go about creating the following...
7
by: Robert | last post by:
Thanks George, I really am grateful for attempts to be helpful, but this really doesn't answer the question in my OP. What I am looking for is an explanation of WHY things are this way (I was...
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.