none
Custom ConfigurationSection

    Question

  • Hello, I'm trying to create a custom configuration section and I succeeded to create the following which was quite straightforward.

     

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <configSections>
      <section name="SimpleElement" type="AppConfig_Extended.SimpleElementConfigurationSection, AppConfig_Extended" />
     </configSections>
     <SimpleElement>
      <Complex id="1" />
      <Complex id="2" />
     </SimpleElement>
    </configuration>

     

    To create the required classes for that kind of structure these were the steps I've taken.

     

    A. Inherit the ConfigurationElement class and create a property which implements the id attribute for the <Complex /> element.

    B. Inherit the ConfigurationElementCollection class and  implement the required methods for the collection.

    C. Inherit the ConfigurationSection class and return an instance of the collection class we made.

     

    Tested and it's all good.

     

    Now I have a problem to create a custom configuration section for the following structure.

     

    <configuration>
     <configSections>
      <section name="SimpleElement" type="AppConfig_Extended.SimpleElementConfigurationSection, AppConfig_Extended" />
     </configSections>
     <SimpleElement>
      <ComplexA>
       <Item>content</Item>
       <Item>more content</Item>
      </ComplexA>
      <ComplexB>
       <Item>content</Item>
       <Item>more content</Item>
      </ComplexB>
     </SimpleElement>
    </configuration>

     

    Can anyone give me a hint here ? Smile

     

    Best Regards.

    Thursday, April 17, 2008 12:16 AM

Answers

  • Below are the only recommendation i can give. but actually your xml file is already okay. i just change the attribute name as item1 and item2 so when you read the element you'll be able to index what attribute you wanted to get. my suggestion is just more on developers but your file i think is already okay. Cheers.

     

    <configuration>
     <configSections>
      <section name="SimpleElement" type="AppConfig_Extended.SimpleElementConfigurationSection, AppConfig_Extended" />
     </configSections>
     <SimpleElement>
      <ComplexA>
       <Item1>content</Item1>
       <Item2>more content</Item2>
      </ComplexA>
      <ComplexB>
       <Item1>content</Item1>
       <Item2>more content</Item2>

      </ComplexB>
     </SimpleElement>
    </configuration>

    Thursday, April 17, 2008 2:17 AM