Skip to content
Jimmy Cushnie edited this page Nov 12, 2019 · 7 revisions

Complex Types are any types that are not base types or collection types.

SUCC will save all the members of a complex type that meet the following criteria:

  • the member is a field or property
  • the member is not static
  • the member can be both read and written to
  • the member is public or has SUCC.DoSaveAttribute defined - see Custom Complex Type Rules
  • the member does not have SUCC.DontSaveAttribute defined - see Custom Complex Type Rules
  • the member is not an indexer

These members will be saved as child key nodes in the SUCC file, using the name of the member for the key.

Note that SUCC can only save complex types which have a parameterless constructor, as it needs this to create the empty types that it then fills with reflection.

See also: Complex Type Shortcuts

Example

using System.Collections.Generic;
using SUCC;

class NPC
{
    public string name;
    public string profession;
    public int health;
}

static class Program
{
    static void Main()
    {
        var characters = new List<NPC>()
        {
            new NPC()
            {
                name = "Garret",
                profession = "Builder",
                health = 100
            },
            new NPC()
            {
                name = "Kevin",
                profession = "Bear",
                health = 100
            },
        };

        var file = new DataFile("test");
        file.Set("characters", characters);
    }
}
characters:
    -
        name: Garret
        profession: Builder
        health: 100
    -
        name: Kevin
        profession: Bear
        health: 100