views:

797

answers:

2

I am creating some C# tools for the game I am working on, and I'm adding the "recent files->" drop down menu.

The problem is, I can't get C#'s "Settings" page in VS2008 to allow me to add a typed HashSet. There's just no option to do it.

I got all hackalicious and manually edited the "Settings.Designer.cs" file to:

    [global::System.Configuration.UserScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public global::System.Collections.Generic.HashSet<String> RecentLibs {
        get {
            return ((global::System.Collections.Generic.HashSet<String>)(this["RecentLibs"]));
        }
        set {
            this["RecentLibs"] = value;
        }
    }

That appears to work just fine. However, I know that at some point it's going to nuke those changes with the code generator.

What's the right way to do this? Does C# have some built in type that I should be using for this functionality rather than just a simple HashSet?

+3  A: 

Don't do it this way. VS will nuke any code in Settings.Designer.cs.

Instead, open the Settings editor from VS (this will show the Design editor for the Settings.settings and Settings.Designer.cs file).

Then, press F7 to get the Code View. VS will automagically create a file called Settings.cs which is a partial class shared with Settings.Designer.cs file. This file you can edit to your heart's content.

Your XML entries in the Settings.settings file may get toasted, however. I'd keep a separate copy of those just in case.

Alan McBee
Very nice to know - I have also been bitten by the lack of generic support in `Settings` - thanks!
jnylen
A: 

Not sure about a 'correct' way to do this, but you can safely move your code to a partial Settings.cs class file without worrying about having Visual Studio overwrite them.

Steve Willcock