Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactor/Move String to App.Config Key

Both Visual Studio 2013 and ReSharper offer many convenient shortcuts for refactoring code. One I commonly use is ReSharper's "Move String To Resource File", which moves a hard-coded string a *.resx file in your project.

Unfortunately, ReSharper doesn't provide "App.config" as an option among the list of resource files to move to.

Does anyone know how to enable or create a "Move/Convert String to App.Config Key" refactoring using either VS or ReSharper?

like image 816
Buffalo Avatar asked Jun 13 '15 23:06

Buffalo


1 Answers

Config management is always going to be specific to the program, and in many cases the build system. Not all programs read strait from the app/web config. In fact sometimes you want to create a class or interface that provides your configuration options. As such,I don't think ReSharper is going to provide an easy way to do what your asking.

You can create a macro to move your text to be consistent with the config approach you have taken.However, its going to be a developers role to update the config value, and update the build variables(i.e if you have a config value for a connection string, that needs to be updated by the build system if moving between different builds).

If you do take the macro approach, you can put in a default value in your macro, so that the config overrides the default value, but you dont have to update the config.

i.e

ConfigurationManager.AppSettings["Config_value"]?? "Default_Value";
like image 172
Bostwick Avatar answered Sep 25 '22 14:09

Bostwick