Skip to content
Merged
Prev Previous commit
Next Next commit
use NullableBool in _supportsRandomAccess
  • Loading branch information
jozkee authored and github-actions committed Oct 12, 2021
commit a9674d021374c34644d2d86dedd2c5290f29763b
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed partial class SafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid

// not using bool? as it's not thread safe
private volatile NullableBool _canSeek = NullableBool.Undefined;
private volatile NullableBool _supportsRandomAccess = NullableBool.Undefined;
private bool _deleteOnClose;
private bool _isLocked;

Expand All @@ -33,11 +34,18 @@ private SafeFileHandle(bool ownsHandle)

internal bool CanSeek => !IsClosed && GetCanSeek();

private bool? _supportsRandomAccess;
internal bool SupportsRandomAccess
{
get => _supportsRandomAccess ??= CanSeek;
set => _supportsRandomAccess = value;
get
{
if (_supportsRandomAccess == NullableBool.Undefined)
{
_supportsRandomAccess = GetCanSeek() ? NullableBool.True : NullableBool.False;
}

return _supportsRandomAccess == NullableBool.True;
}
set => _supportsRandomAccess = value ? NullableBool.True : NullableBool.False;
}

internal ThreadPoolBoundHandle? ThreadPoolBinding => null;
Expand Down