Change calling object with extension method

Hello,
I’ve tried creating a very simple function:

public static void AssignIfNull(this UnityEngine.Object o, UnityEngine.Object obj)
{
   if (o == null)
   {
       Debug.Log(obj);
       o = obj;
       Debug.Log(o);
   }
}

However, while Debug.Log(o) outputs the correct object, the real object doesn’t change. Is it possible to set the calling object to something else with an extension method?

As much as it probably looks like this should work, both parameters are still being passed by copy, meaning although you are changing the object reference, you’re only changing it in the local context of the function. Luckily enough, according to the C# docs;

Beginning with C# 7.2, you can add the ref modifier to the first argument of an extension method.

Meaning in theory you should be able to change the function to something like this;

public static void AssignIfNull (ref this UnityEngine.Object o, UnityEngine.Object obj)
{
    if (o == null)
    {
        Debug.Log(obj);
        o = obj;
        Debug.Log(o);
    }
}

Haven’t tried this personally, so there may be some logical thing I’m overlooking here, but this is how I would think of going about it.

This is what I was getting at. I can do that, but Extension methods with ref are impossible at the moment, and I’m still not entirely convinced that they should be.