-
Notifications
You must be signed in to change notification settings - Fork 161
Configuration Namespace
CUL comes with a simple system to help with getting information out of various configuration files. For instance, it can get information from the web.config or app.config files (it uses that by default). It also has classes to help with XML based or JSON based config files.
In order to access the configuration system you use the following bit of code:
var Config=Utilities.Configuration.ConfigurationManager.Get<Utilities.Configuration.Manager.Default.SystemConfig>();
The code above uses the configuration manager to get the config file information for the web.config/app.config file. That object will contain app settings and connection strings. You can also use JSON or XML files for configuration:
public class TestClass : Utilities.Configuration.JSONConfig<TestClass>
{
public TestClass()
: base()
{
A = "A";
B = "B";
}
public string A { get; set; }
public string B { get; set; }
public override string Name
{
get { return "Test1"; }
}
protected override string ConfigFileLocation
{
get
{
return "./Test.config";
}
}
}
This defines a config file using JSON that is located at Test.config. In order to actually use the class you can do the following:
dynamic ExampleObj = Utilities.Configuration.ConfigurationManager.Get<TestClass>("Test1");
This loads the TestClass object with the associated name Test1 (or the class we created above). We can then set the properties A and B or add properties on the fly. Then when you call Save, it will save the object. Load, well, loads the object again from disk. Note that the example above already has the file loaded.