views:

30

answers:

1

When modifying a .NET settings file, I'm given a choice of types for a setting. However, not all of the types accessible by my project appear, even in the 'Browse' window.

What determines if a type can be used for a setting file setting?

I have a type I created that I would like to be able to save, and I want to know what I need to change about it to use it in a settings file.

(VS 2008 - .Net 3.5)

A: 

What you need to do is "hack" around with the .settings and .Designer.cs files a little, as documented here.

If you create a custom type in your project, such as:

namespace MyApp
{
    public struct MyType
    {
        public string StringValue;
    }
}

To get it to show up as an option in the Settings editor, you need to add the first setting value that uses that type to the files, as follows:

SettingsFile.settings:

<Setting Name="SettingNameGoesHere" Type="MyApp.MyType" Scope="User">
  <Value Profile="(Default)" />
</Setting>

SettingsFile.Designer.cs

[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::MyApp.MyType SettingNameGoesHere {
    get {
        return ((global::MyApp.MyType)(this["SettingNameGoesHere"]));
    }
    set {
        this["SettingNameGoesHere"] = value;
    }
}
Rob
Blech! Some "homemade" types appear in the regular designer - without doing this hacking. Just not the one I want. Why do those appear without hacking?
Mashmagar
I *think* that it doesn't pick up types that are in the same assembly/project. i.e. Any types that are in *other* assemblies that you reference will be available
Rob
@Rob p.s. The 'Blech!' was not targeted at you, but is just my discomfort with mucking around in designer code.
Mashmagar
@Mashmagar, I guessed that - the thought of hand-hacking the files doesn't do much for me either =)
Rob