Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / February 2007

Tip: Looking for answers? Try searching our database.

How identify object by Interface type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
moondaddy - 26 Feb 2007 20:30 GMT
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

Signature

moondaddy@noemail.noemail

Jon Skeet [C# MVP] - 26 Feb 2007 20:42 GMT
> I'm writing a .net3.0 WPF app in c# and want to determin if an object
> implements a certain interface something like this:
[quoted text clipped - 8 lines]
> Where ISelectable is the interface I'm looking for.  In otherwords, how do I
> determin if 'elem' implements ISelectable?

if (elem is ISelectable)

Signature

Jon Skeet - <skeet@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

Keith Patrick - 26 Feb 2007 22:34 GMT
You can also use Type.IsAssignableFrom (if you have the type but not the
object ref)
moondaddy - 27 Feb 2007 20:21 GMT
Thanks Jon,

That was too easy!

>> I'm writing a .net3.0 WPF app in c# and want to determin if an object
>> implements a certain interface something like this:
[quoted text clipped - 11 lines]
>
> if (elem is ISelectable)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.