Skip to content

This library is developed to provide similar functionality to Java's java.util.Properties class.

License

Notifications You must be signed in to change notification settings

bolorundurowb/PropertyConfig

Repository files navigation

PropertyConfig

Build, Test & Cover Coverage Status Method Parity NuGet Badge

Description

This library is developed to provide similar functionality to Java's java.util.Properties class. It allows for the flat storing of name-value pairs in XML.

Usage

Get the library from Nuget by using your package manager or by running;

Install-Package PropertyConfig.dll

Add the directive to your class file:

using PropertyConfig;

Instantiate the class (preferably in the main entry class and storing it in a static variable)

public static Properties configuration = new Properties();

Add whatever properties necessary, for example

configuration["Hello"] = "World";
//or 
configuration.Add("Hello", "World");

After including every property, save the configuration

configuration.StoreToXml(); //saves to the default 'config.xml'
//or
configuration.StoreToXml("my-config.xml"); //saves to specified xml file
//or
configuration.StoreToXml("my-config.xml", "Do not modify manually"); // saves to specified file with additional comment

this produces an output that looks like

<properties>
  <!--Do not modify manually-->
  <Hello>World</Hello>
</properties>

To load a config file

configuration.LoadFromXml() //loads from default 'config.xml'
//or
configuration.LoadFromXml("my-config.xml"); //loads config key-value pairs from the specified file