How identify object by Interface type

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

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
 
moondaddy said:
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)
 
You can also use Type.IsAssignableFrom (if you have the type but not the
object ref)
 
Back
Top