Yesterday we need a customized configuration section in my application and I don’t want write xml schema and C# code for configuration loadingJ. My required configuration pattern for the application
is give below.
<configuration>
<configSections>
<section name="platformProvider" type="xxx.Configuration.Design.PlatformProvider, xxx.Configuration.Design" />
</configSections>
<platformProvider xmlns="urn:xxxx.Configuration.Design" name="Azure">
<services name="Main Services">
<service name="fam">
<settings name="fam_setting">
<values name="fam_values">
<value data="fam_data_1" name="1"></value>
<value data="fam_data_2" name="2"></value>
</values>
</settings>
<modules name="fam_module">
<types name="fam_types">
<type name="IfamCache" assembly="IfamCache_Ass"></type>
<type name="IfamTrans" assembly="IfamTrans_Ass"></type>
</types>
</modules>
</service>
</services>
</platformProvider>
</configuration>
|
If we need to load the above configuration in our application we need to writing different classes and verify them all manually. Thank God I found a very useful add-in for Visual Studio 2010 called Configuration Section Designer and it’s free. You only need to installed CSD add-in and open the new project under the option General -> Configuration Section Project.

Fig 1: Design your customized configure using Configuration Section Designer
When your design is finished press save button and it will prompt you to save the file. When it’s done a xxx.dll file will be created in the bin folder. Now open the Solution Explorer Window and then open nested files.

Fig 2: C# and schema files are showing in the Solution Explorer.
So you are ready to test your dll in your sample application. Add Reference in your sample project and start writing code that manipulates your custom section.
xxx.Configuration.Design.PlatformProvider providers = (xxx.Configuration.Design.PlatformProvider)ConfigurationManager.GetSection("platformProvider");
string str = providers.Services.Name;
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Platform Name '{0}'.", providers.Name);
Console.WriteLine("Platform Services Name '{0}'.", providers.Services.Name);
foreach (xxx.Configuration.Design.Service service in providers.Services)
{
Console.WriteLine("Implementated Service Name '{0}'.", service.Name);
foreach (xxx.Design.Value setting in service.Settings.Values)
{
Console.WriteLine("Setting {0}={1}, for implementated Service Name '{2}'.", setting.Name, setting.Data, service.Name);
}
foreach (xxx.Configuration.Design.Type type in service.Modules.Types)
{
Console.WriteLine("Module {0}={1}, for implementated Service Name '{2}'.", type.Name, type.Assembly, service.Name);
}
}
|
Fig 3: Configuration access code.

Fig 4: Configuration Output.
Aun this is very nice tool I was wrong.