Config file properites

Hey All!

I need to create in app.config sth like this:

<Accounts>

<Account UserName="John" />

<Account UserName="Fred" />

</Accounts>

So it will be a custom section.

I tried to get help on it in MSDN Library but after creating custom section I got:

<MyCustomSection>

<Accounts>

<add UserName="John" />

<add UserName="Fred" />

</Accounts>

</MyCustomSection>

It's pretty good :) But I don't want this <add UserName.. . instead I'd like to have nice <Account> tag what I should change My code is based on ConfigElement example from MSDN instead of URLS I put accounts and I simplified it a lot so I don't put code here.

If you can just tell me what should be collection of what or maybe what class I should create for it to work.

TIA

Jarod



Answer this question

Config file properites

  • James S. Jan

    When I looked at the sample for the Configuration Section (http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx), it looked like the code is doing what you're trying to accomplish.

    I suspect the problem that you're encountering has to do with the base class you're using for MyCustomSection. If the link doesn't help you out, post part of your code and I'll take a closer look.



  • regthesk8r

    I've no idea how it works but it works. Many thanks :)

    Jarod


  • ChitownDotNet

    Take a deeper look :) I'd like to have many <Account> element in <Accounts>. In this case I can have only one <myChildSection>.

    Jarod


  • smk_k

    Have a look at the ConfigurationCollectionAttribute you've got defined on your collection, it should look something like:

    [ConfigurationCollection(typeof(AccountCollection), AddItemName = "Account", CollectionType = ConfigurationElementCollectionType.BasicMap)]



  • Config file properites