Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Type In Application Settings

Tags:

c#

types

settings

I've looked around and nothing has helped so far.

I currently have this code:

namespace InstaShot
{
    [Serializable]
    public class Hotkey
    {
        public uint Modifier { get; private set; }
        public int Key { get; private set; }
        public Hotkey(uint modifier, int key)
        {
            this.Modifier = modifier;
            this.Key = key;
        }
    }
}

Yet whenever I try and create a setting in my application settings, I get:

Type 'InstaShot.Hotkey' is not defined.

When clearly it is... It works for other classes inside the same namespace, just not that one... it's really annoying me now.

like image 371
user1769205 Avatar asked Oct 23 '12 18:10

user1769205


1 Answers

Though the question author has likely moved on it is worth posting an answer in case others come across the same issue.

First let me clarify the question since comments on the question indicate there was some ambiguity. The OP is not asking about custom configuration sections. Rather, the question is about using standard settings--the settings pane you get when you open the Settings tab on the project properties in Visual Studio, as shown:

standard Visual Studio project settings

As to the answer, you must add a default constructor, i.e. a no-argument constructor where you assign default values. Once I did that, I was able to specify the type to get the result shown in the figure above. (Note that if your custom type is in the same assembly as your settings, it will not appear in the list of available types when you open the dropdown in the settings designer, nor--once you select browse--will it appear in that list either, but at that point you can type in the fully qualified name.)

like image 82
Michael Sorens Avatar answered Sep 23 '22 15:09

Michael Sorens