Making a input parameter and object accept multiple types

I am writing my own custom component in c#. I would like one of my inputs to potentially take multiple types. I know to use the AddGenericParameter for my InputParams. What I am struggling with is creating the variable to set to the input.

Basically, the input (rcobject) should be one of three types: RCItem, RCSubAssembly, or RCAssembly. Each of these has an attribute (rcobject.passport) can be loaded into an RCMaterialPassportData object (passport) . The goal is to have a single input parameter that is one of these three types, then is loaded into the RCMaterialPassportData. However, I can’t seem to assign the rcobject in such a way that it will accept my .passport attribute call. Bellow is my code for the SolveInstance:

protected override void SolveInstance(IGH_DataAccess DA)
        {
            // define placeolder variables

            string n = "";
            string loc = "";
            object rcobject;
            
            RCMaterialPassportData data = new RCMaterialPassportData();

            // Assign input to corresponding variables

            if (!DA.GetData(0, ref n)) return;
            if (!DA.GetData(1, ref loc)) return;
            if (!DA.GetData(2, ref rcobject)) return;

            // Algorithm
            if (rcobject.GetType() == ("RCItem" or "RCSubAssembly" or "RCAssembly"))
            {
                data.Load(rcobject.passport);
            }

            else return;

            // Outputs
            DA.SetData(0, data);

        }```

I have also tried assigning rcobject as a var to no success.

You should be using IGH_GeometricGoo and than check for the type.

IGH_GeometricGoo rcobject;

if (rcobject is GH_Curve curve)
{

}
a.s.o.

Kindest
Christian

I tried you code as suggested. Unfortunately it didn’t quite work. When I try to assign the input to that variable, I get an error “Use of unassigned local variable”. Maybe you can see what the problem is.

            string n = "";
            string loc = "";
            IGH_Goo rcobject;
           // IGH_Goo rcobject = null;   this alternate line seemed to work but IDK why 
            RCMaterialPassportData data = new RCMaterialPassportData();

            // Assign input to corresponding variables

            if (!DA.GetData(0, ref n)) return;
            if (!DA.GetData(1, ref loc)) return;
            if (!DA.GetData(2, ref rcobject)) return; //this is the line with the error

//everything beow here seems to work without error
            if (rcobject is RCItem item)
            {
                data.Load(item);
            }
            else if (rcobject is RCSubAssembly subA)
            {
                data.Load(subA);
            }
            else if (rcobject is RCAssembly assembly)
            {
                data.Load(assembly);
            }

What is RCItem, RCSubAssembly a.s.o. - are those your own datatypes?

Try IGH_Goo rcobject = null;