Reputation: 8335
I've been poking around in some projects written by one of our contractors, and he seems to be storing a lot of settings in the main "app.config" file for the application, using, for example:
<add key="SomeClass/SomeValue" value="False"/>
And then referencing the key value in the "SomeClass" class in "SomeProjectLibrary" using
ConfigurationManager.AppSettings.Get("SomeClass/SomeValue")
While this works, I guess, it also pretty much sucks. I was wondering if anyone knew of some more elegant way of creating variables in the "app.config" file, which could then be used across various applications within a Solution?
Hopefully I'm just missing something blindingly obvious.
Upvotes: 0
Views: 549
Reputation: 14387
Well you could make a utility class that you will us for reading your config file. If you put this class in a separate project (say, a utilities project) then you could reference this project from all your other projects. For example:
Public NotInheritable Class ConfigReader
Private Shared reader As New AppSettingsReader()
Public Shared ReadOnly Property SomeValue() As String
Get
Return reader.GetValue("SomeClass/SomeValue", GetType(String)).ToString()
End Get
End Property
//etc..
Usage:
string someValue = ConfigReader.SomeValue
Upvotes: 1