Speckle-Kits and Client-Code object representations

Hey Guys I am thinking of developing a Speckle-Kit but I struggle to figure out how many representations I need for my Data. Imagine I have a c# project with some data types I want to move around through speckle. One way is to create a speckle-Kit. So let’s say my data can be described by this class and lives on the main project (AwesomeProject).

public class Pt
{
    public double X;
    public double Y;
}

Next I need to create a speckle-kit for this data type. So here I go again…but now on a different project.

public class AwesomeProject_Pt : SpeckleObject
{
    public override string Type { get; set; } = "AwesomeProject_Pt";
    public double X;
    public double Y;
}

What goes through my mind is that this is slightly problematic, because I now need to maintain two different projects with essentially the same data.

  1. Now I can see an obvious work around, would be to ditch my first class and just use the one that extends the SpeckleObject but then I am including on my data some very Speckle Specific properties + people using my code will have to work with Speckle as well adding to the complexity.

  2. Another neater solution might be, that since there is a lot of repetition, we can have a post-build event that auto-generated the Speckle-Kit for you and publishes a new .dll so that Speckle would like it. This seems simple so I wonder if anyone else has done it / is seeing some obvious problems with that?

  3. And finally (!), there could be some sort of smartness from the Speckle-side for objects with primitive or known objects. So you can say if on my Kits folder I have a .dll with some classes (maybe they implement something like an interface?) I can then investigate and see if I can convert them to SpeckleObjects through magic of course. The point being is that things might not be pretty, but you can convert them without much of a problem.

  4. Do I just use json and pass a string to Speckle? :smiley: Am I now losing a few things there though? Like auto instantiating objects on the different clients etc…?

I feel like all of them have advantages / disadvantages and I was wondering if you guys have any thoughts on what is the best way to proceed!

Sorry for the long post (does anyone now if we can host potatoes on Speckle streams?) ! I am hoping this has a very obvious answer that I am missing :sweat_smile:

Heya Stam! Running behind on some issues, but what I would do if I were you is just go for an easier variation of (1) - just strap an inheritance on SpeckleObject on your original class & add a type discriminator. Like:

public class Pt : SpeckleObject
{
    public override string Type { get; set; } = "TheBestPoint";
    public double X;
    public double Y;
}

IIRC, when checking for kits/objects, Speckle might look into the currently loaded assemblies in the app domain. If not, then it’s a 2.0 thing…

There’s a bit of docs here on bootstraping your own speckle kit..

Re (4) not sure where you want that to happen. That’s essentially deserialisation, and it won’t work with “just json strings” as Speckle will freak out when looking for which type to deserialize it into. You can though, of course, just use a base raw unmodified SpeckleObject and shove everything in the properties part (it’s just a Dictionary<string, object>), as long as your values are serializable.

1 Like