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 / CLR / May 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry Minton - 25 Apr 2006 17:18 GMT
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,
Larry
Greg Young [MVP] - 26 Apr 2006 02:05 GMT
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)

> 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,
[quoted text clipped - 12 lines]
> Thanks,
> Larry
Larry Minton - 28 Apr 2006 14:01 GMT
Greg,

Thank you for your response.

Larry
Ben Voigt - 03 May 2006 00:40 GMT
> 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)

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.

>> 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,
[quoted text clipped - 12 lines]
>> Thanks,
>> Larry
Larry Minton - 04 May 2006 06:44 GMT
>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.

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...

Larry

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.