Click here to Skip to main content
13,097,230 members (53,639 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 8 Sep 2013

Cinchoo - Support of Complex Object as Configuration Value

, 8 Sep 2013
Rate this:
Please Sign up or sign in to vote.
Consuming and storing complex user defined object as configuration member values


Cinchoo is an application framework for .NET. One of the main functionalities it provides to users is the application configuration management. Application configuration is information that an application reads and/or writes at run-time from the source.

Please visit jump start article [Cinchoo - Simplified Configuration Manager] for more information about Cinchoo configuration manager.

In this section, I’ll detail about a new feature, using and saving custom user defined object as configuration values. So far, Cinchoo framework supports only scalar text values. It limits the configuration object member values from having any complex objects.

In standard .NET Framework, it is not supported in a straight way. You will have to create custom configuration section and put a plumbing code to parse the values. In Cinchoo framework, it is simplified to handle the complex objects as configuration values.

Here is how you can define configuration members to support custom user defined type.

How to Use

  • Download latest Cinchoo binary here.
  • Open VS.NET 2010 or higher.
  • Create a sample VS.NET (.NET Framework 4) Console Application project.
  • Add reference to Cinchoo.Core.dll
  • Use the Cinchoo.Core.Configuration namespace.
  • Define a configuration object 'AppSettings' as below:
public class AppSettings : ChoConfigurableObject
	[ChoPropertyInfo("name", DefaultValue = "Tom")]
	public string Name;

	DefaultValue="10, River Road, Piscataway, NJ 08880 && New York")]
	public ChoCDATA Address;

	DefaultValue = "<Sample>ABCD Inc.</Sample>")]
	public string Employer;

	public Department Department;

	protected override void OnAfterConfigurationObjectLoaded()

In the above sample configuration object, Department member is defined as Department type, it is defined as below:

public class Department : INotifyPropertyChanged
	private int _deptCode;
	public int DeptCode
		get { return _deptCode; }
			_deptCode = value;
	private string _deptName;
	public string DeptName
		get { return _deptName; }
			_deptName = value;
	public event PropertyChangedEventHandler PropertyChanged;
	protected void RaisePropertyChanged(string propertyName)
		if (propertyName.IsNullOrWhiteSpace()) return;
		PropertyChangedEventHandler propertyChanged = PropertyChanged;
		if (propertyChanged != null)
			propertyChanged(this, new PropertyChangedEventArgs(propertyName));

Key things to remember when you define custom object in order to use in configuration object:

  • Should be decorated as ChoXmlSerializerConverter which helps to serialize the object to XML string.
  • Must implement INotifyPropertyChanged in order to notify member changes to Configuration Manager.
  • Decorate appropriate XML serialization attribute to its members (i.e., XmlAttribute, XmlElement, etc.)

Now let's try to create and consume the above configuration object. The below code shows how to consume and modify the object members:

static void Main(string[] args)
	AppSettings appSettings = new AppSettings();
	//Modify the members
	appSettings.Address.Value = "11, Oak Road, Woodbridge, NJ 08827";
	appSettings.Employer = "<Sample1>ZZZ1 Inc.</Sample1>";
	if (appSettings.Department == null)
		appSettings.Department = new Department() 
		{ DeptCode = 10, DeptName = "Comp Sc." };
		appSettings.Department.DeptCode = appSettings.Department.DeptCode + 20; 

If you compile and run this sample, the output of the configuration will be seen as below:

<?xml version="1.0" encoding="utf-8"?>
    <section name="appSettings" 

    type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, Cinchoo.Core" />
    <add key="name" value="Tom" />
    <add key="address">
      <value><![CDATA[11, Oak Road, Woodbridge, NJ 08827]]></value>
    <add key="employer">
        <Sample1>ZZZ1 Inc.</Sample1>
    <add key="department">
        <Department deptCode="11" deptName="Comp Sc." />

That’s it folks, it is as easy as to store and consume custom user defined member in Configuration object.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 8 Sep 2013
Article Copyright 2013 by Cinchoo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid