Using an UserDictionary to store arbitrary data types

Using the UserDictionary on layers and objects is easy if you know what type you’re storing. What I’d like to do is be able to store arbitrary types, both Geometric and non-Geometric. I’d like to avoid TryCast-ing to every known data type accepted by the ArchivableDictionary class. I’ve tried using GH_ObjectWrapper and casting using the dynamic keyword with no luck.

My next test will be to separate GeometricGoo from Goo types and convert all Goo to strings.

Additionally, I’d like to be able to store custom data types not represented in the ArchivableDictionary…

Any thoughts?

Thanks,
Marc

Is the casting because you don’t want to type all the different cases or because you’re worried about performance?

The former – I heard laziness is a virtue for a programmer, trying to live the dream.

I’m not sure, there’s a lot of special casing type code in Grasshopper, have never really been able to make C#/VB work in a non-strongly-typed way to my liking. You could try to see how far dynamic gets you, but it’s hardly reliable.

You can also try to Reflect your way over all the Set overrides and harvest the supported types that way. Benefit of that approach is that it’ll keep working even when we add more types.