I'm implementing IDisposable, and in my Dispose() method when calling Dispose() on other managed resources I'm using the ?. operator like so:
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if(disposing)
{
_ChangeLock?.Dispose();
}
}
I'm still getting the following code analysis error:
CA2213: 'MyClass' contains field 'MyClass._ChangeLock' that is of IDisposable type: 'ReaderWriterLockSlim'. Change the Dispose method on 'MyClass' to call Dispose or Close on this field.
If I change to a standard null check, the code analysis warning goes away:
if(_ChangeLock != null)
_ChangeLock.Dispose();
Is there something wrong with using the null-conditional operator the way I am, or is this code analysis rule outdated, or what?