Line 227: |
Line 227: |
| For example, here's a mod which doubles the sale price of all items: | | For example, here's a mod which doubles the sale price of all items: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
− | public class ModEntry : Mod
| + | internal sealed class ModEntry : Mod |
| { | | { |
| /// <inheritdoc/> | | /// <inheritdoc/> |
Line 246: |
Line 246: |
| var data = asset.AsDictionary<int, string>().Data; | | var data = asset.AsDictionary<int, string>().Data; |
| | | |
− | foreach (int itemID in data.Keys.ToArray()) | + | foreach ((int itemID, string itemData) in data) |
| { | | { |
− | string[] fields = data[itemID].Split('/'); | + | string[] fields = itemData.Split('/'); |
| fields[1] = (int.Parse(fields[1]) * 2).ToString(); | | fields[1] = (int.Parse(fields[1]) * 2).ToString(); |
− | data[itemID] = string.Join("/", fields); | + | data[itemID] = string.Join('/', fields); |
| } | | } |
| }); | | }); |
Line 257: |
Line 257: |
| } | | } |
| </syntaxhighlight> | | </syntaxhighlight> |
− |
| |
− | Note that you'll run into errors if you try to edit the collection you're iterating over. The <samp>ToArray()</samp> avoids that by iterating over a copy of the keys instead.
| |
| | | |
| The <samp>IAssetData asset</samp> argument from the <samp>Edit</samp> method has some helpers to make editing data easier, documented below. (See IntelliSense for more info.) | | The <samp>IAssetData asset</samp> argument from the <samp>Edit</samp> method has some helpers to make editing data easier, documented below. (See IntelliSense for more info.) |