Overriding GH_Component's PostConstructor()

Since the documentation is warning against overriding GH_Component’s PostConstructor()if not knowing what you’re doing”, I felt I should ask if it’s safe to override the method like so?:

    GH_Component Component; 

    protected override void PostConstructor()

        // This fake Component variable allows the code from a 
        // ScriptComponent code to run, unmodified, also if pasted 
        // into a Visual Studio version of the code
        Component = this; 

I think I know what I’m doing, but is there more to it than this?

// Rolf

What’s the earliest point in time when you need this additional functionality? The PostConstructor call into RegisterInputParams and RegisterOutputParams, so you could also do your work there.

Or you could convert your Component variable into a readonly field which just returns this:

protected GH_Component Component { get { return this; } }

Or you could assign the field from its declaration:

protected readonly GH_Component Component = this;

I think class level fields have their assignments run before the constructor is called.

Early. Before RegisterInputParams (which is the main reason why I need the “Component” variable used in the ScriptComponent in the first place)

Yup, this looks like the best alternative. I will put this into the ScriptCodegen_CS2VS component which spits out a VS version.

// Rolf