Skip to content

Commit

Permalink
Fix IDE0031 (use null propagation)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/coreclr@5ea8e2d
  • Loading branch information
stephentoub committed Aug 17, 2019
1 parent cdb164e commit b6e6318
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception? exc

public virtual int GetOffset(int i) { return rgiOffset![i]; }
public virtual int GetILOffset(int i) { return rgiILOffset![i]; }
public virtual string? GetFilename(int i) { return rgFilename == null ? null : rgFilename[i]; }
public virtual string? GetFilename(int i) { return rgFilename?[i]; }
public virtual int GetLineNumber(int i) { return rgiLineNumber == null ? 0 : rgiLineNumber[i]; }
public virtual int GetColumnNumber(int i) { return rgiColumnNumber == null ? 0 : rgiColumnNumber[i]; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ internal static void AssignAssociates(

composedOfAllPrivateMethods = (attributes & Attributes.ComposedOfAllPrivateMethods) != 0;

other = (otherList != null) ? otherList.ToArray() : null;
other = otherList?.ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,7 @@ public void AddArguments(Type[]? arguments, Type[][]? requiredCustomModifiers, T
{
for (int i = 0; i < arguments.Length; i++)
{
AddArgument(arguments[i],
requiredCustomModifiers == null ? null : requiredCustomModifiers[i],
optionalCustomModifiers == null ? null : optionalCustomModifiers[i]);
AddArgument(arguments[i], requiredCustomModifiers?[i], optionalCustomModifiers?[i]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override Type? CatchType
{
Type? declaringType = _methodBody._methodBase.DeclaringType;
Module module = (declaringType == null) ? _methodBody._methodBase.Module : declaringType.Module;
type = module.ResolveType(_catchMetadataToken, (declaringType == null) ? null : declaringType.GetGenericArguments(),
type = module.ResolveType(_catchMetadataToken, declaringType?.GetGenericArguments(),
_methodBody._methodBase is MethodInfo ? _methodBody._methodBase.GetGenericArguments() : null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal bool Unregister(
{
if (ValidHandle())
{
result = UnregisterWaitNative(GetHandle(), waitObject == null ? null : waitObject.SafeWaitHandle);
result = UnregisterWaitNative(GetHandle(), waitObject?.SafeWaitHandle);
if (result == true)
{
if (bReleaseNeeded)
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ private void Heapsort(int lo, int hi)
private void DownHeap(int i, int n, int lo)
{
object d = keys[lo + i - 1];
object? dt = (items != null) ? items[lo + i - 1] : null;
object? dt = items?[lo + i - 1];
int child;
while (i <= n / 2)
{
Expand Down Expand Up @@ -1802,7 +1802,7 @@ private void InsertionSort(int lo, int hi)
{
j = i;
t = keys[i + 1];
ti = (items != null) ? items[i + 1] : null;
ti = items?[i + 1];
while (j >= lo && comparer.Compare(t, keys[j]) < 0)
{
keys[j + 1] = keys[j];
Expand Down Expand Up @@ -1978,7 +1978,7 @@ private void Heapsort(int lo, int hi)
private void DownHeap(int i, int n, int lo)
{
object? d = keys.GetValue(lo + i - 1);
object? dt = (items != null) ? items.GetValue(lo + i - 1) : null;
object? dt = items?.GetValue(lo + i - 1);
int child;
while (i <= n / 2)
{
Expand Down Expand Up @@ -2010,7 +2010,7 @@ private void InsertionSort(int lo, int hi)
{
j = i;
t = keys.GetValue(i + 1);
dt = (items != null) ? items.GetValue(i + 1) : null;
dt = items?.GetValue(i + 1);

while (j >= lo && comparer.Compare(t, keys.GetValue(j)) < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public string? CultureName
{
get
{
return (_cultureInfo == null) ? null : _cultureInfo.Name;
return _cultureInfo?.Name;
}
set
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public OffsetAndRule GetOneYearLocalFromUtc(int year)
if (oneYearLocFromUtc == null || oneYearLocFromUtc.Year != year)
{
TimeZoneInfo currentYear = GetCurrentOneYearLocal();
AdjustmentRule? rule = currentYear._adjustmentRules == null ? null : currentYear._adjustmentRules[0];
AdjustmentRule? rule = currentYear._adjustmentRules?[0];
oneYearLocFromUtc = new OffsetAndRule(year, currentYear.BaseUtcOffset, rule);
_oneYearLocalFromUtc = oneYearLocFromUtc;
}
Expand Down

0 comments on commit b6e6318

Please sign in to comment.