Inheriting from Archivable Dictionary

Hey there Rhino Fans,

I use ArchivableDictionaries quite extensively for my plugin, and I just walked in on quite an intriguing bit of functionality I’d really like to play with more that I have not found written about or documented anywhere, but does seem to work.

It would seem that ArchivableDictionary can be inherited from, and that new class can be saved like a normal ArchivableDictionary WITH any properties attributed to it also returned. See below code, I tested this in GH and a few other ways to ensure it wasn’t just a strange fluke.

// My New Dictionary Class
public class CheekyDictionary: ArchivableDictionary
{
  public string MyValue { get; set; }

  public CheekyDictionary(string value)
    :base()
  {
    MyValue = value;
  }

}
// My Grasshopper C# Component Code
public class Script_Instance : GH_ScriptInstance
{

  private void RunScript(ref object A)
  {
    ArchivableDictionary ad = new ArchivableDictionary();
    ad.Set("test", new CheekyDictionary("nah this wont work"));

    A = ad; // Prints an IEnumerable<KeyValuePair>> as per GH outputs
    B = (ad.GetDictionary("test") as CheekyDictionary).MyValue; // Prints MyValue
  }
}

My questions are this;

  • Is this intentional? And if so, have you ever tried this?
  • Is this safe?
  • I seem to be ble to store anything in this custom ArchivableDictionary and read it back, so I’m assuming the entire thing is serialized to Binary, so as long as I don’t change the class that its serializing too, it should work?
  • Now that I’ve found this, will the ArchivableDictionary be sealed, or can I be on my merry way using this in some core code?

Slight update, it would seem that these CustomDictionaries do not Serialize back when saving/closing and reopening the Document. Is there a way to make this work? :slight_smile:

– cs