all groups > dotnet clr > april 2006 >
You're in the

dotnet clr

group:

Detecting "this XXX in not supported by this YYY" via reflection?


Detecting "this XXX in not supported by this YYY" via reflection? Larry Minton
4/25/2006 12:18:47 PM
dotnet clr:
Is there a way to tell via reflection whether a class does not support
an event/method/property defined in a base class? For example,
consider:

WebBrowser Events:
Event: Click
Description: This event is not supported by this control. (Inherited
from WebBrowserBase)

We are automatically hooking up event handlers to events, and are
getting System.NotSupportedException exceptions when trying to hook up
to such events. So far, I haven't been able to figure out a way to
exclude these types of events.

Thanks,
Re: Detecting "this XXX in not supported by this YYY" via reflection? Greg Young [MVP]
4/25/2006 9:05:41 PM
No as a general rule there is no good way to do this unless thought is put
in ahead of time to either place a "NonImplementedAttribute" or to have an
interface which defines whether or not functionalities are available (i.e.
Stream.CanSeek)


[quoted text, click to view]

Re: Detecting "this XXX in not supported by this YYY" via reflection? Larry Minton
4/28/2006 9:01:46 AM
Greg,

Thank you for your response.

Larry

Re: Detecting "this XXX in not supported by this YYY" via reflection? Ben Voigt
5/2/2006 6:40:04 PM

[quoted text, click to view]

Of course catching a NotSupportedException is far more efficient than
reflection, potentially even more efficient than checking a return value
because exception handling is outside the critical path.

[quoted text, click to view]

Re: Detecting "this XXX in not supported by this YYY" via reflection? Larry Minton
5/4/2006 1:44:40 AM
[quoted text, click to view]

It depends on the problem being solved. If you read my initial
message, having a NonImplementedAttribute would be much more
efficient. No point in trying to attach to the event if the event
isn't supported...

AddThis Social Bookmark Button