Archivable Dictionary - storing an `object` in the UserDictionary [solved]


(Dimitrie) #1

Hello all, I’m upping the game for Speckle’s user data utils ( and I need some loving advice…

Question number one: is there an all encompassing type that has UserDictionary as a property? I’m getting really lost around, especially when it comes to points & polylines, boxes (understand they are structs, but…).

Question number two: I’m generally trying to set stuff in UserDictionarys of RhinoCommon objects - generic (serializable) stuff, usually. Nevertheless, this obviously fails, and I’m forced to do quite a long dance when it comes to casting things around back and forth.

More to the point:

  • Would it be possible to have a .SetObject(ISerliazable obj) method?
  • Wouldn’t it be wonderful if the ArchivableDictionary would just be a simple Dictionary<string, ISerializable>?

I’m sure there’s valid internal reasons that escape my limited knowledge, but I’m curious.

thanks! :sunny:

(Steve Baer) #3

Hi Dimitrie,
The ArchivableDictionary supports a fixed set of types. One of them is a byte array which you could use to save/restore generic data. Here’s a StackOverflow post on converting objects to byte arrays

The ArchivableDictionary property is defined on the Rhino.Runtime.CommonObject class so it should be available to any class that derives from CommonObject

(Dimitrie) #4

Hey steve,
ah sweet, why didn’t i think of that? I’m already converting to byte[] complicated nurbs stuff to send back and forth, why didn’t I think of doing the same here? :man_facepalming: