473,395 Members | 1,452 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,395 software developers and data experts.

How identify object by Interface type

I'm writing a .net3.0 WPF app in c# and want to determin if an object
implements a certain interface something like this:

UIElement elem = GetObjectClicked(e.source as DependancyObject)

if(elem.type==ISelectable)
{
return elem;
}

Where ISelectable is the interface I'm looking for. In otherwords, how do I
determin if 'elem' implements ISelectable?

Thanks

--
mo*******@noemail.noemail
Feb 26 '07 #1
3 1454
moondaddy <mo*******@noemail.noemailwrote:
I'm writing a .net3.0 WPF app in c# and want to determin if an object
implements a certain interface something like this:

UIElement elem = GetObjectClicked(e.source as DependancyObject)

if(elem.type==ISelectable)
{
return elem;
}

Where ISelectable is the interface I'm looking for. In otherwords, how do I
determin if 'elem' implements ISelectable?
if (elem is ISelectable)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 26 '07 #2
You can also use Type.IsAssignableFrom (if you have the type but not the
object ref)

Feb 26 '07 #3
Thanks Jon,

That was too easy!

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
moondaddy <mo*******@noemail.noemailwrote:
>I'm writing a .net3.0 WPF app in c# and want to determin if an object
implements a certain interface something like this:

UIElement elem = GetObjectClicked(e.source as DependancyObject)

if(elem.type==ISelectable)
{
return elem;
}

Where ISelectable is the interface I'm looking for. In otherwords, how
do I
determin if 'elem' implements ISelectable?

if (elem is ISelectable)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Feb 27 '07 #4

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

Similar topics

1
by: Brad H McCollum | last post by:
I'm writing an application using VB 6.0 as the front-end GUI, and the MSDE version of SQL Server as the back-end (it's a program for a really small # of users --- less then 3-4). I'm trying to...
8
by: serge calderara | last post by:
Dear all, I need to be sure that a loaded assembly is implementing a particular interface. How can I do that as long as my assembly is loaded and I have the assemlby object available in...
8
by: DraguVaso | last post by:
Hi, I want my application do different actions depending on the exception it gets. For exemple: I have an SQL-table with a unique index. In case I try to Insert a record that's alreaddy in it I...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
5
by: Sunny | last post by:
Hi, I have to implement client/server application. The client have to instaniate an remoting object via http and pass some auth info. If the auth is OK, the client should invoke a method (or...
11
by: Robin Tucker | last post by:
I have a COM object, which implements straightforwardly the IDataObject interface. It seems this isn't the same IDataObject interface we now have with .NET. Basically, the COM object implements...
15
by: mr.peteryu | last post by:
Hi, Can someone explain the idea behind casting to an interface? For example: -> I have an IInterface that contains a Read() method. -> I have an object "obj" that implements IInterface. ...
3
by: Sam | last post by:
Hi I am trying to create a arraylist of Intefaces so I only need to create each once and I would like to be able to identify the specific interface when I loop thru ??? Is there some way to...
5
by: Random | last post by:
How can I use reflection (or some other method) to find the type of an object that has been passed in to my method under an interface definition? I try to use GetType, but that won't work.
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.