c# - How to have two setting.settings file with the same setting name for default and user config -


i have 2 .settings file. 1 default value of setting , other 1 user choice. 2 settings file contained same setting name not same value.

maybe solution not need 2 .settings file idea have.

in brief, want able propose user choose return default value after has choose bad setting usage.

edit :

i use visual studio 2010 , in win form project

all how restore default configuration when setting.settings file has been changed user choices (how save these default config)

the settingsproperty object each user setting (or setting) can obtained through properties collection on settings class. can @ defaultvalue property default value (the value before being set particular user. example, if you'd access property this:

var value = properties.settings.default.mysetting; 

then can @ default value this:

var defaultvalue = properties.settings.default.properties["mysetting"].defaultvalue; 

the default value 1 set in settings editor in visual studio.

update:

i'm not aware of other way of getting default values. avoid string property name, write extension method default value based on compiler-checked expression:

public static class settingsextensions {     public static t getsettingdefaultvalue<t, t2>(this t2 settings,         expression<func<t2, t>> expression) t2 : applicationsettingsbase     {         memberexpression memberexpr = expression.body memberexpression;         return (t)settings.properties[memberexpr.member.name].defaultvalue;     } } 

and default value this:

var defaultvalue = settings.default.getsettingdefaultvalue(s => s.mysetting); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -