Partager via


Client Settings - Part 3

RichB has some interesting questions in his comments about my earlier post on the client settings feature. I thought it might be worth a separate post to answer them.

I don't have the CTP available, but from the documentation it appears that ApplicationSettingsBase can read and write to a collection of providers. I can understand the writing to multiple providers (saving the same values into multiple locations) but how does it read the same values from multiple locations.

Yes, a settings class can talk to multiple providers, but each setting (or property) in it is associated with a single provider. This just means that you can have different providers for different settings in a settings class.

I also hope you have a good "story" for plug-in based applications. For example, Lutz Roeder's Reflector and Nikhil's Web Matrix are both heavily pluggable. Is there a prescribed way for each plug-in/component to obtain and save configuration information to the same store?

Yes, we have a story for this scenario. There is an interface called IPersistComponentSettings that any component can implement to save its own settings when hosted in an application. For example, the ToolStrip control implements this. Someone using the ToolStrip in their app can just set a property called SaveSettings to true and the ToolStrip will save/restore settings automatically without the user having to set anything up.

I'm also a bit hazy on Setting Groups. I've noticed the SettingsGroupNameAttribute - but am not entirely clear on how it's meant to be used.

Usually, the settings class name is used to identify your settings in the store. If you want them stored with a different name or share settings with some other class, you can use the SettingsGroupNameAttribute to rename/redirect your settings.

Finally, do you have generic methods for loading from the store to prevent boxing?

No, but that's a good suggestion. We will consider doing this.

Comments

  • Anonymous
    July 28, 2005
    Hi Prabhu,

    I had seen your client settings blog from part1 to part3, in all of these you are explaining about the ApplicationSettingsBase but I want to write my own custom SettingsProvider class. please help me out in
    How to write a custom SettingsProvider class?I am asking this question as we could not able to get any links explaining it in better way. If you can provide any samples that will be helpful and also please provide us a solution how to set this custom SettingsProvider to the application, so that application reads the settings from the custom SettingsProvider rather than default LocalFileSettingsProvider

    Thanks
    MDeevi.
  • Anonymous
    July 29, 2005
    I have replied to your question here: http://blogs.msdn.com/rprabhu/archive/2005/06/29/434007.aspx
  • Anonymous
    August 30, 2005
    The comment has been removed
  • Anonymous
    August 30, 2005
    The comment has been removed
  • Anonymous
    February 24, 2006
    The comment has been removed
  • Anonymous
    February 25, 2006
    Hmm, it appears to be running into a null ToolStripItem. Not sure why. I would recommend contacting Jessica (ToolStrip developer) through her blog at http://blogs.msdn.com/jfoscoding to see if she can help.

    Alternately, you could report this issue through MSDN Product Feedback - you can usually expect to get a quick response that way.
  • Anonymous
    May 31, 2006
    Hi Prabhu

    I have property which is of type class x and is an array.  It does not serialize and complains that class x is not defined as serializable.  Here's what class x looks like:

    namespace xSettings
    {
    [Serializable]
    public class x
    {
     private string FName;
     private string FAddress;

     public string Name{ get {return FName;} } set {FName = value;} }
     public string Address{ get {return FAddress;} } set {FAddress = value;} }
    }
    }

    and is defined in xApp application settings as follows:

    Name -> MyList
    Type -> xSettings.x[]
    Scope -> User

    And in code, (C#) I save this way:

    Settings.Default.MyList = arrList;
    Settings.Default.Save();

    How can I save arrays?

    TIA
    Nayan
  • Anonymous
    June 07, 2006
    Nayan:
    Hmm, this should work, but there are some subtleties around the VS settings designer.

    I have moved to a different team in Microsoft a few months back, so I am not in touch with this stuff. I recommend contacting Johan Stenberg through his blog - http://blogs.msdn.com/johan_stenbergs_blog/ - he may be able to help. In fact, he might already have a post which answers your question.