Click here to Skip to main content
15,891,925 members
Articles / Desktop Programming / Win32

Cinchoo - Using Windows registry as configuration source

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
25 Jan 2013CPOL3 min read 9.7K   74   5  
This article show how to consume Windows registry information using Cinchoo Configuration Manager.
namespace ChoRegistrySectionHandler.Test
{
	#region NameSpaces

	using System;
    using Cinchoo.Core.Configuration;
    using Cinchoo.Core;
    using Cinchoo.Core.Shell;
    using Microsoft.Win32;
    using System.Collections.Generic;
    using System.Text;

    #endregion NameSpaces

	[ChoTypeFormatter("Application Settings")]
	[ChoRegistryConfigurationSection("registrySectionHandlerTest/applicationSettings", @"HKCU\Software\Test")]
	public class ApplicationSettings : ChoConfigurableObject
	{
		#region Instance Data Members (Public)

        [ChoPropertyInfo("STREET")]
        public string Street = "25, Melbloum Lane";

		[ChoPropertyInfo("CITY", DefaultValue = "Edison")]
		public string City;

		[ChoPropertyInfo("STATE", DefaultValue = "NJ")]
		public string State;

		[ChoPropertyInfo("ZIP", DefaultValue = "08837")]
		public string Zip;

		[ChoPropertyInfo("BYTE_ZIP", DefaultValue = "1, 0")]
        [ChoMemberRegistryInfo(RegistryValueKind.Binary)]
        [ChoTypeConverter(typeof(ChoByteArrayToStringConverter))]
        public byte[] ByteZip;

		[ChoPropertyInfo("MULTI_VALUE", DefaultValue = "L1, L2")]
		[ChoMemberRegistryInfo(RegistryValueKind.MultiString)]
        [ChoTypeConverter(typeof(ChoArrayToStringConverter))]
		public string[] MultiValue;

        [ChoPropertyInfo("EXP_STRING", DefaultValue = @"%WinDir%\Raj")]
        [ChoMemberRegistryInfo(RegistryValueKind.ExpandString)]
        public string ExpString;

		[ChoPropertyInfo("DWORD_VALUE", DefaultValue = "123")]
		[ChoMemberRegistryInfo(RegistryValueKind.DWord)]
		public int DWordValue = 123;

        [ChoPropertyInfo("QWORD_VALUE", DefaultValue = "64")]
        [ChoMemberRegistryInfo(RegistryValueKind.QWord)]
        public Int64 QWordValue = 123;

		#endregion

		[ChoAfterConfigurationObjectLoadedHandler]
		void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
		{
			using (ChoConsoleSession console = new ChoConsoleSession(ConsoleColor.Green))
			{
				console.WriteLine(sender.ToString());
			}
		}

		[ChoConfigurationObjectLoadErrorHandler]
        void OnConfigurationObjectLoadError(object sender, ChoConfigurationObjectErrorEventArgs e)
		{
			using (ChoConsoleSession console = new ChoConsoleSession(ConsoleColor.Red))
			{
				console.WriteLine(e.Exception.ToString());
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions