free geoip ApplicationSettingsBase.[Insert Event Name Here] Discrepancy - Jayson's Blog - jaysonKnight.com
jaysonKnight.com
Welcome to my corner of the internet
ApplicationSettingsBase.[Insert Event Name Here] Discrepancy

Microsoft has done a good job when it comes to event naming within the BCL by following a common naming pattern: the gerund form of the verb is used during the act of doing something (i.e. Form.Closing), whereas the past tense is used after the act has completed (ala Form.Closed).  They've also done a fairly good job of encapsulating the full lifetime of events for a set of actions, and it's fairly intuitive to find what you are looking for in the documentation.

Recently I've been fooling around with the application settings classes in a Windows Forms application, but noticed a deviation from this practice for reasons that are beyond me, specifically the events exposed by the ApplicationSettingsBase class.  I'll let you glance at the list for a second or two, the missing event should be pretty obvious.  I'll wait...

 

Figure it out?  There is no corresponding SettingsSaved event.  Granted how I was going to use an event like that if it existed may be just flat out wrong from a design standpoint, but it certainly would feel right if that event existed, and there's a lot to be said about writing code that feels right.  In this case I need to have some configuration settings that are being saved from an options form applied immediately to various controls, so it makes sense not only to go ahead and apply the new changes, but persist them to disk as well.  This is easy enough to code around by using my own events, but it's still a little odd that MS excluded is, especially since there is a SettingsSaving event.  Puzzling.


Posted Fri, Jan 26 2007 2:44 AM by Jayson Knight

Comments

Thomas Freudenberg wrote re: ApplicationSettingsBase.[Insert Event Name Here] Discrepancy
on Fri, Jan 26 2007 3:58 AM

Why should your controls rely on a SettingsSaved event? As far as I understand your description, they only need to subscribe to the PropertyChanged event. They shouldn't need to know whether the settings are persisted to disk or not.

Jayson Knight wrote re: ApplicationSettingsBase.[Insert Event Name Here] Discrepancy
on Fri, Jan 26 2007 5:47 AM

No, they don't need to know that...however the PropertyChanged event doesn't expose what the new value is via the PropertyChangedEventArgs (you can get the name of the setting only).

The SettingsChangingEventArgs class does indeed expose the new value, which I did not realize until after I made this post. It's a little kludgier than it would be to just read the settings back in from disk, but it has the side effect of being much faster of course.

So, this functionality is indeed exposed from the BCL, it's just not as obvious as it should be ;-). I'll post my workaround soon.

protected virtual void jaysonBlog { wrote ApplicationSettingsBase Event Issue -- Solution
on Fri, Jan 26 2007 4:18 PM

In my last post about the apparent strangeness going on with the lack of a SettingsSaved event, I may

Add a Comment

(optional)  
(optional)
(required)  
Remember Me?

Copyright © :: JaysonKnight.com
External Content © :: Respective Authors

Terms of Service/Privacy Policy