How to create a custom section that behaves like an AppSettings section?

后端 未结 2 2016
旧时难觅i
旧时难觅i 2021-02-20 01:58

I want to have the following structure in my config:

  
    
  
  &l         


        
2条回答
  •  不知归路
    2021-02-20 02:24

    This worked --
    Code:

    class Program
    {
        static void Main(string[] args)
        {
            NameValueCollection nvc = ConfigurationManager.GetSection("MyAppSettings") as NameValueCollection;
            for(int i=0; i

    Configuration:

    
    
      
        
        

    My major concern was that my section needed to inherit from a custom section and I wanted to return a NameValueCollection when the ConfigurationManager.GetSection("MyAppSettings") is called.
    I changed the type property to AppSettingsSection, even though it's nowhere in the picture and it worked. Now I need to figure out how that worked but for now the good thing is that I have a working sample :)

    Update: Unfortunately, this wasn't the expected way of achieving what was intended because now the custom section is not coming into the picture at all so unfortunately this isn't the best way to do it.

    Of course, if you just wanted to rename your appsettings section this would work like a charm.

提交回复
热议问题