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’m going to detail about a new feature, using and saving CDATA / XML as configuration values. So far, Cinchoo supports the configuration object member values as simple text values. It limits the configuration object member values from having any complex text.
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, it is simplified to handle CDATA/XML values.
Here is how you can define configuration members to support CDATA / XML values.
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
- Define a configuration object '
ApplicationSettings' as below:
public class AppSettings : ChoConfigurableObject
[ChoPropertyInfo("name", DefaultValue = "Tom")]
public string Name;
River Road, Piscataway, NJ 08880 && New York")]
public ChoCDATA Address;
DefaultValue = "<Sample>ABCD Inc.</Sample>")]
public string Employer;
In the above sample configuration object, Address member defined as
ChoCDATA type to accommodate
CDATA value. Employer member is defined as
string type, to hold the XML value. Cinchoo automatically checks the configuration member value for any XML tags present, if it does then the section value will be created as XML element, otherwise it will be created as XML attribute.
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();
appSettings.Address = new ChoCDATA("11, Oak Road, Woodbridge, NJ 08827");
appSettings.Employer = "<Sample1>ZZZ1 Inc.</Sample1>";
CDATA member, any modification must be done by creating new
ChoCDATA object with new value and assign to it. And for the
Employer member, it is straight forward to modify. Cinchoo framework will take care of it under the hood.
If you compile and run this sample, the output of the configuration will be seen as below:
type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, Cinchoo.Core" />
<add key="name" value="Tom" />
That’s all folks, it is as easy as storing and consuming CDATA / XML values in