Question about ActionScheduler.cs

In the StartAction method wouldn’t this be a better code solution??? the way Sam does it make’s it a problematic in Rider. It calls it a resource dependent and errors. So I refactored to the below code.

    public void StartAction(IAction action)
    {
        if (currentAction == action) return;
        currentAction?.Cancel();
        currentAction = action;
    }

I use Jetbrains ReSharper (basically a plugin that has the same refactoring knowledge as Ryder). It throws a similar warning.
Interestingly enough, when the compiler converts this to IL, it will do the same thing. Both methods work.

One thing you do need to know about Null propogation, it has limits. Simple method calls like this will work fine. Complex statements like method chaining or any assignments won’t work.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.