Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Replace several Nullable<T>.Value with .GetValueOrDefault() #22297

Merged
merged 1 commit into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private bool CanSeekCore(SafeFileHandle fileHandle)
_canSeek = Interop.Sys.LSeek(fileHandle, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0;
}

return _canSeek.Value;
return _canSeek.GetValueOrDefault();
}

private long GetLengthInternal()
Expand Down
2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/shared/System/IO/FileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void ValidateAndInitFromHandle(SafeFileHandle handle, FileAccess access,

if (handle.IsClosed)
throw new ObjectDisposedException(SR.ObjectDisposed_FileClosed);
if (handle.IsAsync.HasValue && isAsync != handle.IsAsync.Value)
if (handle.IsAsync.HasValue && isAsync != handle.IsAsync.GetValueOrDefault())
throw new ArgumentException(SR.Arg_HandleNotAsync, nameof(handle));

_exposedHandle = true;
Expand Down
12 changes: 6 additions & 6 deletions src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ private static AdjustmentRule TZif_CreateAdjustmentRuleForPosixFormat(string pos
TimeSpan? parsedBaseOffset = TZif_ParseOffsetString(standardOffset);
if (parsedBaseOffset.HasValue)
{
TimeSpan baseOffset = parsedBaseOffset.Value.Negate(); // offsets are backwards in POSIX notation
TimeSpan baseOffset = parsedBaseOffset.GetValueOrDefault().Negate(); // offsets are backwards in POSIX notation
baseOffset = TZif_CalculateTransitionOffsetFromBase(baseOffset, timeZoneBaseUtcOffset);

// having a daylightSavingsName means there is a DST rule
Expand All @@ -1110,7 +1110,7 @@ private static AdjustmentRule TZif_CreateAdjustmentRuleForPosixFormat(string pos
}
else
{
daylightSavingsTimeSpan = parsedDaylightSavings.Value.Negate(); // offsets are backwards in POSIX notation
daylightSavingsTimeSpan = parsedDaylightSavings.GetValueOrDefault().Negate(); // offsets are backwards in POSIX notation
daylightSavingsTimeSpan = TZif_CalculateTransitionOffsetFromBase(daylightSavingsTimeSpan, timeZoneBaseUtcOffset);
daylightSavingsTimeSpan = TZif_CalculateTransitionOffsetFromBase(daylightSavingsTimeSpan, baseOffset);
}
Expand Down Expand Up @@ -1176,7 +1176,7 @@ private static AdjustmentRule TZif_CreateAdjustmentRuleForPosixFormat(string pos

if (result.HasValue && negative)
{
result = result.Value.Negate();
result = result.GetValueOrDefault().Negate();
}
}

Expand All @@ -1193,8 +1193,8 @@ private static DateTime ParseTimeOfDay(ReadOnlySpan<char> time)
// Some time zones use time values like, "26", "144", or "-2".
// This allows the week to sometimes be week 4 and sometimes week 5 in the month.
// For now, strip off any 'days' in the offset, and just get the time of day correct
timeOffset = new TimeSpan(timeOffset.Value.Hours, timeOffset.Value.Minutes, timeOffset.Value.Seconds);
if (timeOffset.Value < TimeSpan.Zero)
timeOffset = new TimeSpan(timeOffset.GetValueOrDefault().Hours, timeOffset.GetValueOrDefault().Minutes, timeOffset.GetValueOrDefault().Seconds);
if (timeOffset.GetValueOrDefault() < TimeSpan.Zero)
{
timeOfDay = new DateTime(1, 1, 2, 0, 0, 0);
}
Expand All @@ -1203,7 +1203,7 @@ private static DateTime ParseTimeOfDay(ReadOnlySpan<char> time)
timeOfDay = new DateTime(1, 1, 1, 0, 0, 0);
}

timeOfDay += timeOffset.Value;
timeOfDay += timeOffset.GetValueOrDefault();
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ private AdjustmentRule GetPreviousAdjustmentRule(AdjustmentRule rule, int? ruleI
{
Debug.Assert(rule.NoDaylightTransitions, "GetPreviousAdjustmentRule should only be used with NoDaylightTransitions rules.");

if (ruleIndex.HasValue && 0 < ruleIndex.Value && ruleIndex.Value < _adjustmentRules.Length)
if (ruleIndex.HasValue && 0 < ruleIndex.GetValueOrDefault() && ruleIndex.GetValueOrDefault() < _adjustmentRules.Length)
{
return _adjustmentRules[ruleIndex.Value - 1];
return _adjustmentRules[ruleIndex.GetValueOrDefault() - 1];
}

AdjustmentRule result = rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ internal static object CreateIReference(object obj)
if (propType.HasValue)
{
Type specificType = typeof(CLRIReferenceImpl<>).MakeGenericType(type);
return Activator.CreateInstance(specificType, new object[] { propType.Value, obj });
return Activator.CreateInstance(specificType, new object[] { propType.GetValueOrDefault(), obj });
}

Debug.Fail("We should not see non-WinRT type here");
Expand Down Expand Up @@ -389,7 +389,7 @@ internal static object CreateIReferenceArray(Array obj)
{
// All WinRT value type will be Property.Other
Type specificType = typeof(CLRIReferenceArrayImpl<>).MakeGenericType(type);
return Activator.CreateInstance(specificType, new object[] { propType.Value, obj });
return Activator.CreateInstance(specificType, new object[] { propType.GetValueOrDefault(), obj });
}
else
{
Expand Down