Changes

m
Added a fix to the example Edit function to avoid an InvalidOperationException, and a note detailing the issue requiring the fix.
Line 210: Line 210:  
         {
 
         {
 
             IDictionary<int, string> data = asset.AsDictionary<int, string>().Data;
 
             IDictionary<int, string> data = asset.AsDictionary<int, string>().Data;
             foreach (int itemID in data.Keys)
+
             foreach (int itemID in data.Keys.ToArray())
 
             {
 
             {
 
                 string[] fields = data[itemID].Split('/');
 
                 string[] fields = data[itemID].Split('/');
Line 220: Line 220:  
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Note that you will run into errors if you attempt to modify the collection you're iterating over. To get around this, we use the ToArray() function as above, to iterate over a copy of the collection instead.
    
The <tt>IAssetData asset</tt> argument for your <tt>Edit</tt> method has some helpers to make editing data easier, documented below. (See IntelliSense for the <tt>asset</tt> argument for more info.)
 
The <tt>IAssetData asset</tt> argument for your <tt>Edit</tt> method has some helpers to make editing data easier, documented below. (See IntelliSense for the <tt>asset</tt> argument for more info.)
11

edits