C
Chris Dunaway
I have an .exe console project and a class library project as part of a
solution. The .exe has an App.config file and I have used the Settings
page to add some Application level settings.
When I try to retrieve a setting using this code:
//Method 1
string s = ConfigurationManager.AppSettings["TestSetting"];
I don't get anything back. But if I use the following code:
//Method 2
Properties.Settings _settings = new
ThrowAwayCs.Properties.Settings();
s = _settings.TestSetting;
I do get the correct value. I like the second method because I get
intellisense for all the settings. The first method seems prone to
error if I have a typo in the code because I will not know about it
until runtime.
I have two questions:
1. Is this way (method 2) of using the Settings class (which is
defined in Settings.Designer.cs) considered appropriate? It seems to
work fine.
2. I would like to use the second method in a class library project
but since the application references the class library, I cannot
reference the app from the class library because of a circular
reference. I would like to have full intellisense for my settings
inside the class libaray. Is this possible?
I would appreciate any comments on how others have used Application
Settings from a class library that is referenced by the app.
Thanks,
Chris
Keywords:
dll
app
settings
reference
intellisense
class library
solution. The .exe has an App.config file and I have used the Settings
page to add some Application level settings.
When I try to retrieve a setting using this code:
//Method 1
string s = ConfigurationManager.AppSettings["TestSetting"];
I don't get anything back. But if I use the following code:
//Method 2
Properties.Settings _settings = new
ThrowAwayCs.Properties.Settings();
s = _settings.TestSetting;
I do get the correct value. I like the second method because I get
intellisense for all the settings. The first method seems prone to
error if I have a typo in the code because I will not know about it
until runtime.
I have two questions:
1. Is this way (method 2) of using the Settings class (which is
defined in Settings.Designer.cs) considered appropriate? It seems to
work fine.
2. I would like to use the second method in a class library project
but since the application references the class library, I cannot
reference the app from the class library because of a circular
reference. I would like to have full intellisense for my settings
inside the class libaray. Is this possible?
I would appreciate any comments on how others have used Application
Settings from a class library that is referenced by the app.
Thanks,
Chris
Keywords:
dll
app
settings
reference
intellisense
class library