Configuration Library - Nested structs/ArrayLists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexandros__

    Configuration Library - Nested structs/ArrayLists

    Hello everyone,

    I am using the Configuration Application block to write an XML
    configuration file for my application. Most of it is working fine but I
    have a problem serialising some nested structs that have arraylist
    fields. What I want to do is to have a ShoppingBasket that will hold
    any number of Itemstructs and an AllShoppingBask ets that will hold all
    the ShoppingBaskets . The resulting XML I am after should look like
    this.

    <AllShoppingBas kets>
    <ShoppingBasket >
    <Item>
    <ItemType>ItemT ype</ItemType>
    <ItemCaption>It emCaption</ItemCaption>
    </Item>
    </ShoppingBasket >
    </AllShoppingBask ets >

    To do this I created
    - an Item struct:
    public struct Item
    {
    public Item(string itemType, string itemCaption)...
    }

    - a ShoppingBasket struct:
    public struct ShoppingBasket
    {
    public ShoppingBasket (ArrayList items)...
    }
    the items Arraylist will hold all the items of the basket.

    - and an AllShopingBaske t struct.
    public struct Stations
    {
    public Stations (ArrayList allBaskets)...
    }
    the allBaskets Arraylist will hold all the ShoppingBaskets where every
    basket will hold Items.

    to serialise the data I am using :
    ConfigurationMa nager.WriteConf iguration("shop pingbasketsetti ngs",
    configData);
    So in the ConfigData Class I have an AllShopingBaske ts property to be
    serialized this way I would get

    <AllShoppingBas kets>
    <AllBaskets>
    <anyType xsi:type="Shopp ingBasket">
    <Items>
    <anyType xsi:type="Item" >
    <ItemType>ItemT ype</ItemType>
    <ItemCaption>It emCaption</ItemCaption>
    </anyType>
    </Items>
    </anyType>
    </AllBaskets>
    </AllShoppingBask ets>

    But if I have to have an Item and a ShoppingBasket as properties in the
    ConfigData class or else I get an XML exception. If I do have those two
    I get the above XML but also XML representations of Items and
    ShopingBaskets which I don't want. If I use [XMLIgnore] on them it
    breaks again.

    Any ideas on what I am doing wrong or suggestion on doing this in a
    different way?

    Cheers

Working...