Can you keep the wires in the input when upgrading a component?

Hi, my problem is that I made an upgrader for a component by using the IGH_UpgradeObject interface.
In the Upgrader function I needed to replace the input parameter to another one.
I made this possible by the following code:


newComp.Params.UnregisterInputParameter(newComp.Params.Input.First());

            
newComp.Params.RegisterInputParam(at_index: 0, new_param: new ModelObjectParam()
            {
                Name =...,
                NickName = ...,
                Description = ...,
                Access = GH_ParamAccess.item
            });

When the Upgrade Component menu option is used the component is replaced to the new one.
But it also looses the input wire.
The new input parameter type is different to teh old one, but it accepts the same data.

Is there a way to keep the wires in the input when upgrading an old component and replacing the input parameter type?

Looks like this is solved here

IF your params change (in my case from Param_Brep to Param_Geometry) you can’t use the MigrateOutputParameters.

In that case you’ll need to iterate manually, see here:

public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
{
    if (!(target is IGH_Component oldComponent)) return null;

    // CACHE OLD SOURCES AND RECEPIENTS
    List<List<IGH_Param>> sources = new List<List<IGH_Param>>();

    foreach (IGH_Param param in oldComponent.Params.Input)
    {
        sources.Add(param.Sources.ToList());
    }


    List<List<IGH_Param>> recepients = new List<List<IGH_Param>>();

    foreach (IGH_Param param in oldComponent.Params.Output)
    {
        recepients.Add(param.Recipients.ToList());
    }


    IGH_Component newComponent = GH_UpgradeUtil.SwapComponents(oldComponent, UpgradeTo, false);

    
    // RECONNECT THE OLD SOURCES AND RECEPIENTS TO NEW COMPONENT
    for (int i = 0; i < sources.Count; i++)
    {
        sources[i].ForEach(s => newComponent.Params.Input[i].AddSource(s));
    }

    for (int i = 0; i < recepients.Count; i++)
    {

        recepients[i].ForEach(r => r.AddSource(newComponent.Params.Output[i]));
        
    }

    //GH_UpgradeUtil.MigrateInputParameters(target as IGH_Component, newComponent, new int[] { 1, 2}, new int[] { 1, 2 });
    //GH_UpgradeUtil.MigrateOutputParameters(target as IGH_Component, newComponent, new int[] { 0 }, new int[] { 0 });


    //newComponent.Params.OnParametersChanged(); // Not needed if you don't change too much
    return newComponent;