Passing Custom Class Objects from one component to another in C#

Hey all,

Can do this all the time with the VB scriptable components, but when I try doing it with c#, it asks for a cast from the system.object.  When I do that

1. [A]Custom_Object cannot be cast to [B]Custom_Object. Type A originates from 'e233189a-7b7e-4eab-8fdf-1bdb1cc50365, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Users\epiermar\AppData\Local\Temp\e233189a-7b7e-4eab-8fdf-1bdb1cc50365.dll'. Type B originates from '7a7dbe0c-0813-4244-845e-7821e9daef59, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Users\epiermar\AppData\Local\Temp\7a7dbe0c-0813-4244-845e-7821e9daef59.dll'. (line: 75)

I've seen that David said in a post a few years ago there's not passing of objects from one component to another in C#.  Is this still the case?  Thanks for the help.

EAP

  • up

    David Rutten

    If you don't output a type which implements IGH_Goo, Grasshopper will try its best to convert your data into goo. When it fails, it will wrap it up in a GH_ObjectWrapper, which is a sort of bare-bones goo type.

    If you don't want your data messed with, then you should put it in a GH_ObjectWrapper yourself and cut out the middle man.

    What you cannot do is share instances of a type which is not known to both the sender code and the recipient code. Outputting an instance of a type which is defined in the sender cannot be converted into that type by the receiver because the receiver doesn't have access to that type definition. So that's the big constraint you have to work around. You can choose to use an existing type, maybe share data as a String or a Dictionary or something.

    1
    • up

      David Stasiuk

      I'd suggest you simply use VS (or VS Express) and compile a simple library where you keep any tools or custom classes that you use with any frequency. Then you just reference your .dll wherever you want to use your classes.

      1