How to perserve data in gh component?

i make a custom component(by c#),and it can be input some data in it in a small the picture…
but every time i restart the rhino,the data stored in it is disapppears…because i dont know how to perserve data in gh file.
of course i can use a data file(may be hidden in C:…) to store file…but it is not so elegant…
can someone has some idea of how to perserve data in gh custom component ?Thank you.

You must override the Read() and Write() methods on your component and include your values in the archive. Be sure to call the base class Read and Write, otherwise you’ll break IO.

You can wrap any code you post in discourse in triple ticks to format it correctly.

string code = “Would look correctly” + " like this.";

results in:

string code = "Would look correctly" + " like this.";

Would it be possible to store entire data tree? @DavidRutten
As a C# novice I’m thinking something like below. FYI variable store is a Dictionary where keys are strings and values are entire GH_Structure<> It’s initialized elsewhere.

public override bool Write(GH_IWriter writer)
    GH_IWriter datastore = writer.CreateChunk("datastore");
    foreach (string key in store.Keys)
        GH_IWriter chunk = datastore.CreateChunk(key);
    return base.Write(writer);
public override bool Read(GH_IReader reader)
    GH_IReader datastore = reader.FindChunk("datastore");
    foreach (GH_IReader chunk in datastore.Chunks)
        GH_Structure<IGH_Goo> tree = new GH_Structure<IGH_Goo>();
        store[chunk.Name] = tree;
    return base.Read(reader);

Apparently this does NOT work. Missing chunk error.