Cinchoo – Configuration framework, part 4

Using ChoFileNameValueConfigStorage

Download sample source files (Require .NET 4.0 / Visual Studio 2010)

In this part, I’ll go over the details of using ChoFileNameValueConfigStorage in your application. It provides name/value-pair configuration information from file source. This is the default configuration storage used by ChoNameValueConfigurationSectionHandlerChoNameValueConfigurationSectionAttribute is the corresponding attribute used to decorate the configuration object class.

1. Define the configuration section object decorated with ChoNameValueConfigurationSectionAttribute as below.

public class SampleConfigSection : ChoConfigurableObject
	#region Instance Data Members (Public)

	[ChoPropertyInfo("name", DefaultValue="Mark")]
	public string Name;

	[ChoPropertyInfo("message", DefaultValue="Hello World!")]
	public string Message;


	void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)

2. Now instantiate and use it as below

class Program
	static void Main(string[] args)
		SampleConfigSection sampleConfigSection = new SampleConfigSection();

The configuration section will be generated automatically for the first time in HelloWorld.exe.xml as below

<?xml version="1.0" encoding="utf-8"?>
    <section name="sample" type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, Cinchoo.Core" />
    <add key="name" value="Mark" />
    <add key="message" value="Hello World!" />

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s