Geeks With Blogs
Saqib Ullah BootStrapper Know How

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.

Posted on Friday, October 14, 2011 5:26 AM .Net | Back to top


Comments on this post: Configuration Section Designer Tool for Visual Studio

# re: Configuration Section Designer Tool for Visual Studio
Requesting Gravatar...
Very nice , manu thaks
Left by Muhannad al Hariri on May 16, 2012 2:18 AM

# re: Configuration Section Designer Tool for Visual Studio
Requesting Gravatar...
Thanks for this Tip, this worked great.
Left by Elisa FA on Jan 29, 2013 10:23 AM

# re: Configuration Section Designer Tool for Visual Studio
Requesting Gravatar...
Thanks. Visual Studio can sometimes be a pain, but this helped me alot.
Left by Lucy on Feb 06, 2013 4:47 AM

# re: Configuration Section Designer Tool for Visual Studio
Requesting Gravatar...
I'm currently working on a new visual studio project. So this will be very useful for me. Many thanks.
Left by Jennifer H on Mar 10, 2013 10:10 PM

# re: Configuration Section Designer Tool for Visual Studio
Requesting Gravatar...
This seems like a useful tool for my Visual Studio project. Thanks for the tipp.
Left by Jana AD on Apr 14, 2013 6:49 AM

# re: Configuration Section Designer Tool for Visual Studio
Requesting Gravatar...
Thats a great guide and it will help with my Design project. Danke aus Bremen
Left by Franzi on Apr 29, 2013 1:24 AM

# re: Configuration Section Designer Tool for Visual Studio
Requesting Gravatar...
This code example seems to be great for my new IT class. I'm sure the students appreciate your blog.
Left by Dana on May 20, 2013 6:56 AM

Your comment:
 (will show your gravatar)


Copyright © Saqib Ullah | Powered by: GeeksWithBlogs.net