Ive got a problem with the current task im working on, and im not sure how is the best way to solve it.
Basically i have an asynchronous loader that loads images from an XML file, so there could be 1 or 100 image links contained. Now to make it slightly harder they need to maintain the order that they are on the XML file. The Images are contained within an object that is partially populated from the XML data, then it has a list<Image> that should be filled with the loaded images as they complete.
So i thought the easiest way to do this would be to make sure that each image has an index of where it resides, so when its loaded it knows where to go in the list. So if there was 100 images and lets say number 67 completed first i was assuming it would just allow me to put it in there, and then as the others fly in it would eventually reach 100, just they get put inserted in a random order.
Now it loves to spit out an error telling me that:
"Index must be within the bounds of the List."
So im assuming that it will only let me insert into an already existing index in the list OR at the end of the list... so is my understanding correct, and if so is there any way to achieve what i want?
I was thinking about maybe having a loop so if you try to insert at an index > list count then it would fill in dummy data to flesh out until that count, but it sounded a little inefficient, so just wanted to see if anyone could think of a better way...
Thing is i dont know how many indexes there will be, there could be 1 or 100, and as the async loaders are set off before the XML has finished parsing you wont know how many indexes there are total until its too late, which is why im using a list as its either that or my own linked list...
Also further down the line there may be new images added after this point so it needs to be able to add and remove things at will, an array does not give that flexibility.
<main_data someatt1="1" someatt2="2">
<parent_X someatt1="1" someatt2="2">
<child_X someatt1="1" someatt2="2" />
... Random Amount of Children
.. Random Amount of Parents
Thats basically the layout of my XML, i have an unknown number of child nodes to the main node, then each one of them can have an unknown amount of nodes. An array would still not be flexible enough to add elements later on, so again i cannot use a default array unless i write some dynamic wrappers for it (a list<>, which already exists).
Ive currently solved it by adding a null element each time an async is fired off, so there is always a relvent index available. At least that way there is minimal alteration to the code flow, and i dont have to do any additional traversing of the XML hierarchy...