-
Notifications
You must be signed in to change notification settings - Fork 15
Collection Types
SUCC supports saving Arrays, Lists, HashSets, and Dictionaries. If there's another collection type you'd like to see SUCC support, please open an issue for it.
Arrays are saved, ordered, as list nodes.
var array = new string[] { "string 1", "string 2", "string 3" };
var file = new DataFile("test");
file.Set("array", array);
array:
- string 1
- string 2
- string 3
Lists are saved the same way as arrays.
HashSets are saved the same way as arrays and lists, but their contents are not in a particular order.
SUCC has two ways of saving Dictionaries. First, there's the standard way, using the keys of the dictionary as keys in the file.
var tools = new Dictionary<string, string>
{
["digging"] = "shovel",
["hitting"] = "hammer",
["succing"] = "vacuum",
};
var file = new DataFile("test");
file.Set("tools", tools);
tools:
digging: shovel
hitting: hammer
succing: vacuum
However, sometimes the keys of a dictionary can't be used as keys in the file, because they are invalid SUCC keys or complex types. When that happens, dictionaries are serialized as an array of key/value pairs.
var opinions = new Dictionary<int, string>
{
[-1] = "not bad",
[0] = "can't be beat for simplicity",
};
var file = new DataFile("test");
file.Set("opinions", opinions);
opinions:
-
key: -1 # "-1" would be an invalid SUCC key because it begins with "-".
value: not bad
-
key: 0
value: can't be beat for simplicity
You can force dictionaries to always be saved in array mode, even if they would work in the standard way, with FileStyle.AlwaysArrayDictionaries.
- Overview
- Installing
- Getting Started
- Advanced Usage
- File Logic
- Version Differences
- Contributing
- Projects Using SUCC