Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDotnet-GitSync-Bot <45578709+Dotnet-GitSync-Bot@users.noreply.github.com>2019-09-06 22:58:38 +0300
committerZoltan Varga <vargaz@gmail.com>2019-09-06 22:58:38 +0300
commit381c187df9a6007e5d843803416e61ffde13b1cf (patch)
tree89328d76bc3623cff2c00914802fb1092cdb745e
parent18fb728c65b806285454af7ef3da0faa7c7160db (diff)
Mirror changes from mono/coreclr (#16713)
* Remove stale SuppressMessage attributes (dotnet/coreclr#26501) Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com> * Use null coalescing assignment operator in more places There's currently no auto-fix for this, so the fixes were done manually. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com> * Fix IDE0026 (use expression-bodied members for indexers) Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AggregateException.cs6
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Array.cs2
-rw-r--r--netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs2
-rw-r--r--netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs6
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs9
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs116
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs4
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs1
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Exception.cs2
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs9
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs85
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs6
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs2
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/Stream.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs6
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Object.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ParamsArray.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs7
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs4
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs2
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs1
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs4
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs1
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/RuntimeType.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs9
-rw-r--r--netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs6
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs3
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs4
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs2
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs7
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs2
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZone.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs5
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Tuple.cs161
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ValueTuple.cs140
63 files changed, 280 insertions, 716 deletions
diff --git a/netcore/System.Private.CoreLib/shared/System/AggregateException.cs b/netcore/System.Private.CoreLib/shared/System/AggregateException.cs
index e24ad1939b0..3486a4fdbf0 100644
--- a/netcore/System.Private.CoreLib/shared/System/AggregateException.cs
+++ b/netcore/System.Private.CoreLib/shared/System/AggregateException.cs
@@ -339,11 +339,7 @@ namespace System
// exceptions (to be rethrown later) and add it.
if (!predicate(m_innerExceptions[i]))
{
- if (unhandledExceptions == null)
- {
- unhandledExceptions = new List<Exception>();
- }
-
+ unhandledExceptions ??= new List<Exception>();
unhandledExceptions.Add(m_innerExceptions[i]);
}
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Array.cs b/netcore/System.Private.CoreLib/shared/System/Array.cs
index d2b9aca96b4..606cf8973d4 100644
--- a/netcore/System.Private.CoreLib/shared/System/Array.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Array.cs
@@ -477,7 +477,7 @@ namespace System
if (array.Rank != 1)
ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
- if (comparer == null) comparer = Comparer.Default;
+ comparer ??= Comparer.Default;
#if CORECLR
if (comparer == Comparer.Default)
{
diff --git a/netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs b/netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs
index f9072e98098..e3edaebb0bd 100644
--- a/netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs
+++ b/netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs
@@ -107,8 +107,7 @@ namespace System
if (_fusionLog != null)
{
- if (s == null)
- s = " ";
+ s ??= " ";
s += Environment.NewLine;
s += Environment.NewLine;
s += _fusionLog;
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs
index 53c7d79dc33..7607145e3a4 100644
--- a/netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs
@@ -811,8 +811,7 @@ namespace System.Collections
if (Count - index < count)
throw new ArgumentException(SR.Argument_InvalidOffLen);
- if (comparer == null)
- comparer = Comparer.Default;
+ comparer ??= Comparer.Default;
int lo = index;
int hi = index + count - 1;
@@ -904,7 +903,6 @@ namespace System.Collections
return _list.IndexOf(value);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int IndexOf(object? value, int startIndex)
{
return IndexOf(value, startIndex, _list.Count - startIndex);
@@ -970,13 +968,11 @@ namespace System.Collections
return LastIndexOf(value, _list.Count - 1, _list.Count);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex)
{
return LastIndexOf(value, startIndex, startIndex + 1);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex, int count)
{
if (_list.Count == 0)
@@ -1216,7 +1212,6 @@ namespace System.Collections
return _list.Capacity;
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
set
{
lock (_root)
@@ -1290,7 +1285,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
{
lock (_root)
@@ -1339,7 +1333,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void CopyTo(int index, Array array, int arrayIndex, int count)
{
lock (_root)
@@ -1356,7 +1349,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override IEnumerator GetEnumerator(int index, int count)
{
lock (_root)
@@ -1373,7 +1365,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int IndexOf(object? value, int startIndex)
{
lock (_root)
@@ -1382,7 +1373,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int IndexOf(object? value, int startIndex, int count)
{
lock (_root)
@@ -1399,7 +1389,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void InsertRange(int index, ICollection c)
{
lock (_root)
@@ -1416,7 +1405,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex)
{
lock (_root)
@@ -1425,7 +1413,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex, int count)
{
lock (_root)
@@ -1450,7 +1437,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void RemoveRange(int index, int count)
{
lock (_root)
@@ -1459,7 +1445,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void Reverse(int index, int count)
{
lock (_root)
@@ -1468,7 +1453,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void SetRange(int index, ICollection c)
{
lock (_root)
@@ -1477,7 +1461,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override ArrayList GetRange(int index, int count)
{
lock (_root)
@@ -1502,7 +1485,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void Sort(int index, int count, IComparer? comparer)
{
lock (_root)
@@ -1519,7 +1501,6 @@ namespace System.Collections
}
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override Array ToArray(Type type)
{
lock (_root)
@@ -1766,7 +1747,6 @@ namespace System.Collections
throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
{
return _list.BinarySearch(index, count, value, comparer);
@@ -1775,7 +1755,6 @@ namespace System.Collections
public override int Capacity
{
get => _list.Capacity;
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
set => throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
}
@@ -1801,7 +1780,6 @@ namespace System.Collections
_list.CopyTo(array, index);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void CopyTo(int index, Array array, int arrayIndex, int count)
{
_list.CopyTo(index, array, arrayIndex, count);
@@ -1812,7 +1790,6 @@ namespace System.Collections
return _list.GetEnumerator();
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override IEnumerator GetEnumerator(int index, int count)
{
return _list.GetEnumerator(index, count);
@@ -1823,13 +1800,11 @@ namespace System.Collections
return _list.IndexOf(value);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int IndexOf(object? value, int startIndex)
{
return _list.IndexOf(value, startIndex);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int IndexOf(object? value, int startIndex, int count)
{
return _list.IndexOf(value, startIndex, count);
@@ -1840,7 +1815,6 @@ namespace System.Collections
throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void InsertRange(int index, ICollection c)
{
throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
@@ -1851,13 +1825,11 @@ namespace System.Collections
return _list.LastIndexOf(value);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex)
{
return _list.LastIndexOf(value, startIndex);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex, int count)
{
return _list.LastIndexOf(value, startIndex, count);
@@ -1873,13 +1845,11 @@ namespace System.Collections
throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void RemoveRange(int index, int count)
{
throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void SetRange(int index, ICollection c)
{
_list.SetRange(index, c);
@@ -1896,14 +1866,12 @@ namespace System.Collections
return new Range(this, index, count);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void Reverse(int index, int count)
{
_list.Reverse(index, count);
_version = _list._version;
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void Sort(int index, int count, IComparer? comparer)
{
_list.Sort(index, count, comparer);
@@ -1915,7 +1883,6 @@ namespace System.Collections
return _list.ToArray();
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override Array ToArray(Type type)
{
return _list.ToArray(type);
@@ -2033,7 +2000,6 @@ namespace System.Collections
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
{
return _list.BinarySearch(index, count, value, comparer);
@@ -2043,7 +2009,6 @@ namespace System.Collections
public override int Capacity
{
get => _list.Capacity;
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
@@ -2069,7 +2034,6 @@ namespace System.Collections
_list.CopyTo(array, index);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void CopyTo(int index, Array array, int arrayIndex, int count)
{
_list.CopyTo(index, array, arrayIndex, count);
@@ -2080,7 +2044,6 @@ namespace System.Collections
return _list.GetEnumerator();
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override IEnumerator GetEnumerator(int index, int count)
{
return _list.GetEnumerator(index, count);
@@ -2091,13 +2054,11 @@ namespace System.Collections
return _list.IndexOf(value);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int IndexOf(object? value, int startIndex)
{
return _list.IndexOf(value, startIndex);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int IndexOf(object? value, int startIndex, int count)
{
return _list.IndexOf(value, startIndex, count);
@@ -2108,7 +2069,6 @@ namespace System.Collections
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void InsertRange(int index, ICollection c)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
@@ -2119,13 +2079,11 @@ namespace System.Collections
return _list.LastIndexOf(value);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex)
{
return _list.LastIndexOf(value, startIndex);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex, int count)
{
return _list.LastIndexOf(value, startIndex, count);
@@ -2141,13 +2099,11 @@ namespace System.Collections
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void RemoveRange(int index, int count)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void SetRange(int index, ICollection c)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
@@ -2163,13 +2119,11 @@ namespace System.Collections
return new Range(this, index, count);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void Reverse(int index, int count)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void Sort(int index, int count, IComparer? comparer)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
@@ -2180,7 +2134,6 @@ namespace System.Collections
return _list.ToArray();
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override Array ToArray(Type type)
{
return _list.ToArray(type);
@@ -2521,13 +2474,11 @@ namespace System.Collections
return -1;
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex)
{
return LastIndexOf(value, startIndex, startIndex + 1);
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int LastIndexOf(object? value, int startIndex, int count)
{
InternalUpdateRange();
@@ -2586,7 +2537,6 @@ namespace System.Collections
InternalUpdateVersion();
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void SetRange(int index, ICollection c)
{
InternalUpdateRange();
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs
index 4234a3ac5f2..888b97688cc 100644
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs
@@ -58,11 +58,7 @@ namespace System.Collections.Generic
// underlying IComparables, etc) that are bogus.
try
{
- if (comparer == null)
- {
- comparer = Comparer<T>.Default;
- }
-
+ comparer ??= Comparer<T>.Default;
IntrospectiveSort(keys, index, length, comparer.Compare);
}
catch (IndexOutOfRangeException)
@@ -79,11 +75,7 @@ namespace System.Collections.Generic
{
try
{
- if (comparer == null)
- {
- comparer = Comparer<T>.Default;
- }
-
+ comparer ??= Comparer<T>.Default;
return InternalBinarySearch(array, index, length, value, comparer);
}
catch (Exception e)
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs
index 7253577c097..8a19f04318c 100644
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs
@@ -152,59 +152,17 @@ namespace System.Collections.Generic
public int Count => _count - _freeCount;
- public KeyCollection Keys
- {
- get
- {
- if (_keys == null) _keys = new KeyCollection(this);
- return _keys;
- }
- }
+ public KeyCollection Keys => _keys ??= new KeyCollection(this);
- ICollection<TKey> IDictionary<TKey, TValue>.Keys
- {
- get
- {
- if (_keys == null) _keys = new KeyCollection(this);
- return _keys;
- }
- }
+ ICollection<TKey> IDictionary<TKey, TValue>.Keys => _keys ??= new KeyCollection(this);
- IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys
- {
- get
- {
- if (_keys == null) _keys = new KeyCollection(this);
- return _keys;
- }
- }
+ IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => _keys ??= new KeyCollection(this);
- public ValueCollection Values
- {
- get
- {
- if (_values == null) _values = new ValueCollection(this);
- return _values;
- }
- }
+ public ValueCollection Values => _values ??= new ValueCollection(this);
- ICollection<TValue> IDictionary<TKey, TValue>.Values
- {
- get
- {
- if (_values == null) _values = new ValueCollection(this);
- return _values;
- }
- }
+ ICollection<TValue> IDictionary<TKey, TValue>.Values => _values ??= new ValueCollection(this);
- IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values
- {
- get
- {
- if (_values == null) _values = new ValueCollection(this);
- return _values;
- }
- }
+ IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => _values ??= new ValueCollection(this);
public TValue this[TKey key]
{
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs
index 119d768fc86..6314f5f24dd 100644
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs
@@ -830,15 +830,7 @@ namespace System.Collections
// to the hash table are reflected in this collection. It is not
// a static copy of all the keys in the hash table.
//
- public virtual ICollection Keys
- {
- get
- {
- if (_keys == null)
- _keys = new KeyCollection(this);
- return _keys;
- }
- }
+ public virtual ICollection Keys => _keys ??= new KeyCollection(this);
// Returns a collection representing the values of this hashtable. The
// order in which the returned collection represents the values is
@@ -850,15 +842,7 @@ namespace System.Collections
// to the hash table are reflected in this collection. It is not
// a static copy of all the keys in the hash table.
//
- public virtual ICollection Values
- {
- get
- {
- if (_values == null)
- _values = new ValueCollection(this);
- return _values;
- }
- }
+ public virtual ICollection Values => _values ??= new ValueCollection(this);
// Inserts an entry into this hashtable. This method is called from the Set
// and Add methods. If the add parameter is true and the given key already
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs
index 4791ae7dd80..59f92233267 100644
--- a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs
@@ -26,10 +26,7 @@ namespace System.Collections.ObjectModel
public int Count => list.Count;
- public T this[int index]
- {
- get { return list[index]; }
- }
+ public T this[int index] => list[index];
public bool Contains(T value)
{
diff --git a/netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs b/netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs
index 428464c6c0b..66e8c758875 100644
--- a/netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs
+++ b/netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs
@@ -12,8 +12,6 @@ namespace System.ComponentModel
/// <summary>
/// Specifies the default value for a property.
/// </summary>
- [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments")]
- [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
[AttributeUsage(AttributeTargets.All)]
public class DefaultValueAttribute : Attribute
{
diff --git a/netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs b/netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs
index 2df633396a6..01a94934829 100644
--- a/netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs
+++ b/netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs
@@ -136,14 +136,12 @@ namespace System
private static DaylightTime CreateDaylightChanges(int year)
{
- DaylightTime? currentDaylightChanges = null;
+ DateTime start = DateTime.MinValue;
+ DateTime end = DateTime.MinValue;
+ TimeSpan delta = TimeSpan.Zero;
if (TimeZoneInfo.Local.SupportsDaylightSavingTime)
{
- DateTime start;
- DateTime end;
- TimeSpan delta;
-
foreach (TimeZoneInfo.AdjustmentRule rule in TimeZoneInfo.Local.GetAdjustmentRules())
{
if (rule.DateStart.Year <= year && rule.DateEnd.Year >= year && rule.DaylightDelta != TimeSpan.Zero)
@@ -151,19 +149,12 @@ namespace System
start = TimeZoneInfo.TransitionTimeToDateTime(year, rule.DaylightTransitionStart);
end = TimeZoneInfo.TransitionTimeToDateTime(year, rule.DaylightTransitionEnd);
delta = rule.DaylightDelta;
-
- currentDaylightChanges = new DaylightTime(start, end, delta);
break;
}
}
}
- if (currentDaylightChanges == null)
- {
- currentDaylightChanges = new DaylightTime(DateTime.MinValue, DateTime.MinValue, TimeSpan.Zero);
- }
-
- return currentDaylightChanges;
+ return new DaylightTime(start, end, delta);
}
public override TimeSpan GetUtcOffset(DateTime time)
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs
index c424fc12c14..6b9707fdf10 100644
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs
@@ -640,8 +640,7 @@ namespace System.Diagnostics.Contracts
}
}
- if (probablyNotRewritten == null)
- probablyNotRewritten = thisAssembly;
+ probablyNotRewritten ??= thisAssembly;
string? simpleName = probablyNotRewritten.GetName().Name;
ContractHelper.TriggerFailure(kind, SR.Format(SR.MustUseCCRewrite, contractKind, simpleName), null, null, null);
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs
index 0f476912885..00e080d05c2 100644
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs
@@ -184,8 +184,7 @@ namespace System.Diagnostics.Tracing
if (orphan.CanBeOrphan())
{
// We can't pop anything after we see a valid orphan, remember this for later when we update m_current.
- if (newCurrentActivity == null)
- newCurrentActivity = orphan;
+ newCurrentActivity ??= orphan;
}
else
{
@@ -201,8 +200,7 @@ namespace System.Diagnostics.Tracing
// I succeeded stopping this activity. Now we update our m_current pointer
// If I haven't yet determined the new current activity, it is my creator.
- if (newCurrentActivity == null)
- newCurrentActivity = activityToStop.m_creator;
+ newCurrentActivity ??= activityToStop.m_creator;
m_current.Value = newCurrentActivity;
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
index 6a3d373fe63..a805605fec5 100644
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
@@ -100,7 +100,6 @@ namespace System.Diagnostics.Tracing
private const int s_etwAPIMaxRefObjCount = 8;
private const int s_traceEventMaximumSize = 65482;
- [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
public enum WriteEventErrorCode : int
{
// check mapping to runtime codes
@@ -435,8 +434,7 @@ namespace System.Diagnostics.Tracing
if (val > 1)
return;
- if (sessionList == null)
- sessionList = new List<SessionInfo>(8);
+ sessionList ??= new List<SessionInfo>(8);
if (val == 1)
{
@@ -684,7 +682,6 @@ namespace System.Diagnostics.Tracing
return false;
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public static WriteEventErrorCode GetLastWriteEventError()
{
return s_returnCode;
@@ -957,8 +954,6 @@ namespace System.Diagnostics.Tracing
// <UsesUnsafeCode Name="Local v7 of type: Char*" />
// <ReferencesCritical Name="Method: EncodeObject(Object&, EventData*, Byte*):String" Ring="1" />
// </SecurityKernel>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Performance-critical code")]
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference")]
internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid* activityID, Guid* childActivityID, params object?[] eventPayload)
{
WriteEventErrorCode status = WriteEventErrorCode.NoError;
@@ -1155,7 +1150,6 @@ namespace System.Diagnostics.Tracing
// <SecurityKernel Critical="True" Ring="0">
// <CallsSuppressUnmanagedCode Name="Interop.Advapi32.EventWrite(System.Int64,EventDescriptor&,System.UInt32,System.Void*):System.UInt32" />
// </SecurityKernel>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference")]
protected internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid* activityID, Guid* childActivityID, int dataCount, IntPtr data)
{
if (childActivityID != null)
@@ -1177,7 +1171,6 @@ namespace System.Diagnostics.Tracing
return true;
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference")]
internal unsafe bool WriteEventRaw(
ref EventDescriptor eventDescriptor,
IntPtr eventHandle,
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
index 47839357e2c..c8e718c98a3 100644
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
@@ -248,7 +248,6 @@ namespace System.Diagnostics.Tracing
/// Returns true if the eventSource has been enabled at all. This is the preferred test
/// to be performed before a relatively expensive EventSource operation.
/// </summary>
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
public bool IsEnabled()
{
return m_eventSourceEnabled;
@@ -263,7 +262,6 @@ namespace System.Diagnostics.Tracing
/// positives (but is always accurate when returning false). EventSources are free to
/// have additional filtering.
/// </summary>
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
public bool IsEnabled(EventLevel level, EventKeywords keywords)
{
return IsEnabled(level, keywords, EventChannel.None);
@@ -279,7 +277,6 @@ namespace System.Diagnostics.Tracing
/// positives (but is always accurate when returning false). EventSources are free to
/// have additional filtering.
/// </summary>
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
public bool IsEnabled(EventLevel level, EventKeywords keywords, EventChannel channel)
{
if (!m_eventSourceEnabled)
@@ -743,14 +740,12 @@ namespace System.Diagnostics.Tracing
#pragma warning disable 1591
// optimized for common signatures (no args)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId)
{
WriteEventCore(eventId, 0, null);
}
// optimized for common signatures (ints)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, int arg1)
{
if (m_eventSourceEnabled)
@@ -763,7 +758,6 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, int arg1, int arg2)
{
if (m_eventSourceEnabled)
@@ -779,7 +773,6 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3)
{
if (m_eventSourceEnabled)
@@ -799,7 +792,6 @@ namespace System.Diagnostics.Tracing
}
// optimized for common signatures (longs)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, long arg1)
{
if (m_eventSourceEnabled)
@@ -812,7 +804,6 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, long arg1, long arg2)
{
if (m_eventSourceEnabled)
@@ -828,7 +819,6 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, long arg1, long arg2, long arg3)
{
if (m_eventSourceEnabled)
@@ -848,12 +838,11 @@ namespace System.Diagnostics.Tracing
}
// optimized for common signatures (strings)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, string? arg1)
{
if (m_eventSourceEnabled)
{
- if (arg1 == null) arg1 = "";
+ arg1 ??= "";
fixed (char* string1Bytes = arg1)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[1];
@@ -865,13 +854,12 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2)
{
if (m_eventSourceEnabled)
{
- if (arg1 == null) arg1 = "";
- if (arg2 == null) arg2 = "";
+ arg1 ??= "";
+ arg2 ??= "";
fixed (char* string1Bytes = arg1)
fixed (char* string2Bytes = arg2)
{
@@ -887,14 +875,13 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3)
{
if (m_eventSourceEnabled)
{
- if (arg1 == null) arg1 = "";
- if (arg2 == null) arg2 = "";
- if (arg3 == null) arg3 = "";
+ arg1 ??= "";
+ arg2 ??= "";
+ arg3 ??= "";
fixed (char* string1Bytes = arg1)
fixed (char* string2Bytes = arg2)
fixed (char* string3Bytes = arg3)
@@ -915,12 +902,11 @@ namespace System.Diagnostics.Tracing
}
// optimized for common signatures (string and ints)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, string? arg1, int arg2)
{
if (m_eventSourceEnabled)
{
- if (arg1 == null) arg1 = "";
+ arg1 ??= "";
fixed (char* string1Bytes = arg1)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
@@ -935,12 +921,11 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3)
{
if (m_eventSourceEnabled)
{
- if (arg1 == null) arg1 = "";
+ arg1 ??= "";
fixed (char* string1Bytes = arg1)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
@@ -959,12 +944,11 @@ namespace System.Diagnostics.Tracing
}
// optimized for common signatures (string and longs)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, string? arg1, long arg2)
{
if (m_eventSourceEnabled)
{
- if (arg1 == null) arg1 = "";
+ arg1 ??= "";
fixed (char* string1Bytes = arg1)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
@@ -980,12 +964,11 @@ namespace System.Diagnostics.Tracing
}
// optimized for common signatures (long and string)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, long arg1, string? arg2)
{
if (m_eventSourceEnabled)
{
- if (arg2 == null) arg2 = "";
+ arg2 ??= "";
fixed (char* string2Bytes = arg2)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
@@ -1001,12 +984,11 @@ namespace System.Diagnostics.Tracing
}
// optimized for common signatures (int and string)
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, int arg1, string? arg2)
{
if (m_eventSourceEnabled)
{
- if (arg2 == null) arg2 = "";
+ arg2 ??= "";
fixed (char* string2Bytes = arg2)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
@@ -1021,7 +1003,6 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, byte[]? arg1)
{
if (m_eventSourceEnabled)
@@ -1055,7 +1036,6 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, long arg1, byte[]? arg2)
{
if (m_eventSourceEnabled)
@@ -1163,7 +1143,7 @@ namespace System.Diagnostics.Tracing
/// {
/// if (IsEnabled())
/// {
- /// if (arg2 == null) arg2 = "";
+ /// arg2 ??= "";
/// fixed (char* string2Bytes = arg2)
/// {
/// EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
@@ -1196,7 +1176,7 @@ namespace System.Diagnostics.Tracing
/// {
/// if (IsEnabled())
/// {
- /// if (arg2 == null) arg2 = "";
+ /// arg2 ??= "";
/// fixed (char* string2Bytes = arg2)
/// {
/// EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
@@ -1305,7 +1285,6 @@ namespace System.Diagnostics.Tracing
/// method signature. Even if you use this for rare events, this call should be guarded by an <see cref="IsEnabled()"/>
/// check so that the varargs call is not made when the EventSource is not active.
/// </summary>
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
protected unsafe void WriteEvent(int eventId, params object?[] args)
{
WriteEventVarargs(eventId, null, args);
@@ -1442,7 +1421,6 @@ namespace System.Diagnostics.Tracing
/// "Log", such an exception would become a cached exception for the initialization of the static
/// member, and any future access to the "Log" would throw the cached exception).
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "guid")]
private unsafe void Initialize(Guid eventSourceGuid, string eventSourceName, string[]? traits)
{
try
@@ -1527,8 +1505,7 @@ namespace System.Diagnostics.Tracing
}
catch (Exception e)
{
- if (m_constructionException == null)
- m_constructionException = e;
+ m_constructionException ??= e;
ReportOutOfBandMessage("ERROR: Exception during construction of EventSource " + Name + ": " + e.Message, true);
}
@@ -1577,10 +1554,7 @@ namespace System.Diagnostics.Tracing
/// </summary>
public void Start()
{
- if (this.w == null)
- {
- this.w = new uint[85];
- }
+ this.w ??= new uint[85];
this.length = 0;
this.pos = 0;
@@ -2178,7 +2152,6 @@ namespace System.Diagnostics.Tracing
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
private unsafe void WriteEventString(EventLevel level, long keywords, string msgString)
{
#if FEATURE_MANAGED_ETW
@@ -2658,7 +2631,9 @@ namespace System.Diagnostics.Tracing
{
// We can't do the command, simply remember it and we do it when we are fully constructed.
if (m_deferredCommands == null)
+ {
m_deferredCommands = commandArgs; // create the first entry
+ }
else
{
// We have one or more entries, find the last one and add it to that.
@@ -2706,8 +2681,7 @@ namespace System.Diagnostics.Tracing
throw new ArgumentException(SR.EventSource_ListenerNotFound);
}
- if (commandArgs.Arguments == null)
- commandArgs.Arguments = new Dictionary<string, string?>();
+ commandArgs.Arguments ??= new Dictionary<string, string?>();
if (commandArgs.Command == EventCommand.Update)
{
@@ -2944,8 +2918,7 @@ namespace System.Diagnostics.Tracing
EventDispatcher? dispatcher = m_Dispatchers;
while (dispatcher != null)
{
- if (dispatcher.m_EventEnabled == null)
- dispatcher.m_EventEnabled = new bool[m_eventData.Length];
+ dispatcher.m_EventEnabled ??= new bool[m_eventData.Length];
dispatcher = dispatcher.m_Next;
}
#if FEATURE_PERFTRACING
@@ -3683,8 +3656,7 @@ namespace System.Diagnostics.Tracing
// throw new WarningException(SR.EventSource_EventNameDoesNotEqualTaskPlusOpcode);
// }
- if (eventsByName == null)
- eventsByName = new Dictionary<string, string>();
+ eventsByName ??= new Dictionary<string, string>();
if (eventsByName.ContainsKey(evtName))
{
@@ -3706,7 +3678,6 @@ namespace System.Diagnostics.Tracing
/// </summary>
/// <param name="method">The method to probe.</param>
/// <returns>The literal value or -1 if the value could not be determined. </returns>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Switch statement is clearer than alternatives")]
private static int GetHelperCallFirstArg(MethodInfo method)
{
#if (!ES_BUILD_PCL && !ES_BUILD_PN)
@@ -3835,7 +3806,6 @@ namespace System.Diagnostics.Tracing
/// It will do this even if the EventSource is not enabled.
/// TODO remove flush parameter it is not used.
/// </summary>
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
internal void ReportOutOfBandMessage(string msg, bool flush)
{
try
@@ -4083,7 +4053,6 @@ namespace System.Diagnostics.Tracing
/// call Dispose when they are done with their logging.
/// </summary>
#if ES_BUILD_STANDALONE
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
#endif
public virtual void Dispose()
{
@@ -4263,8 +4232,7 @@ namespace System.Diagnostics.Tracing
{
lock (EventListenersLock)
{
- if (s_EventSources == null)
- s_EventSources = new List<WeakReference>(2);
+ s_EventSources ??= new List<WeakReference>(2);
if (!s_EventSourceShutdownRegistered)
{
@@ -5380,8 +5348,10 @@ namespace System.Diagnostics.Tracing
ManifestError(SR.Format(SR.EventSource_OpcodeCollision, name, prevName, value));
}
}
+
opcodeTab[value] = name;
}
+
public void AddTask(string name, int value)
{
if ((flags & EventManifestOptions.Strict) != 0)
@@ -5396,10 +5366,11 @@ namespace System.Diagnostics.Tracing
ManifestError(SR.Format(SR.EventSource_TaskCollision, name, prevName, value));
}
}
- if (taskTab == null)
- taskTab = new Dictionary<int, string>();
+
+ taskTab ??= new Dictionary<int, string>();
taskTab[value] = name;
}
+
public void AddKeyword(string name, ulong value)
{
if ((value & (value - 1)) != 0) // Is it a power of 2?
@@ -5418,8 +5389,8 @@ namespace System.Diagnostics.Tracing
ManifestError(SR.Format(SR.EventSource_KeywordCollision, name, prevName, "0x" + value.ToString("x", CultureInfo.CurrentCulture)));
}
}
- if (keywordTab == null)
- keywordTab = new Dictionary<ulong, string>();
+
+ keywordTab ??= new Dictionary<ulong, string>();
keywordTab[value] = name;
}
@@ -5445,8 +5416,7 @@ namespace System.Diagnostics.Tracing
ulong kwd = GetChannelKeyword(chValue);
- if (channelTab == null)
- channelTab = new Dictionary<int, ChannelInfo>(4);
+ channelTab ??= new Dictionary<int, ChannelInfo>(4);
channelTab[value] = new ChannelInfo { Name = name, Keywords = kwd, Attribs = channelAttribute };
}
@@ -5535,8 +5505,7 @@ namespace System.Diagnostics.Tracing
{
// mark this index as "extraneous" (it has no parallel in the managed signature)
// we use these values in TranslateToManifestConvention()
- if (byteArrArgIndices == null)
- byteArrArgIndices = new List<int>(4);
+ byteArrArgIndices ??= new List<int>(4);
byteArrArgIndices.Add(numParams);
// add an extra field to the template representing the length of the binary blob
@@ -5556,8 +5525,7 @@ namespace System.Diagnostics.Tracing
if (type.IsEnum() && Enum.GetUnderlyingType(type) != typeof(ulong) && Enum.GetUnderlyingType(type) != typeof(long))
{
templates.Append(" map=\"").Append(type.Name).Append("\"");
- if (mapsTab == null)
- mapsTab = new Dictionary<string, Type>();
+ mapsTab ??= new Dictionary<string, Type>();
if (!mapsTab.ContainsKey(type.Name))
mapsTab.Add(type.Name, type); // Remember that we need to dump the type enumeration
}
@@ -5606,10 +5574,7 @@ namespace System.Diagnostics.Tracing
{
// strip off any non-channel keywords, since we are only interested in channels here.
channelKeyword &= ValidPredefinedChannelKeywords;
- if (channelTab == null)
- {
- channelTab = new Dictionary<int, ChannelInfo>(4);
- }
+ channelTab ??= new Dictionary<int, ChannelInfo>(4);
if (channelTab.Count == MaxCountChannels)
ManifestError(SR.EventSource_MaxChannelExceeded);
@@ -5697,8 +5662,8 @@ namespace System.Diagnostics.Tracing
access = attribs.Access;
#endif
}
- if (fullName == null)
- fullName = providerName + "/" + channelInfo.Name;
+
+ fullName ??= providerName + "/" + channelInfo.Name;
sb.Append(" <").Append(elementName);
sb.Append(" chid=\"").Append(channelInfo.Name).Append("\"");
@@ -5949,8 +5914,7 @@ namespace System.Diagnostics.Tracing
// allow channels to be auto-defined. The well known ones get their well known names, and the
// rest get names Channel<N>. This allows users to modify the Manifest if they want more advanced features.
- if (channelTab == null)
- channelTab = new Dictionary<int, ChannelInfo>(4);
+ channelTab ??= new Dictionary<int, ChannelInfo>(4);
string channelName = channel.ToString(); // For well know channels this is a nice name, otherwise a number
if (EventChannel.Debug < channel)
@@ -5961,8 +5925,8 @@ namespace System.Diagnostics.Tracing
ManifestError(SR.Format(SR.EventSource_UndefinedChannel, channel, eventName));
}
// events that specify admin channels *must* have non-null "Message" attributes
- if (resources != null && eventMessage == null)
- eventMessage = resources.GetString("event_" + eventName, CultureInfo.InvariantCulture);
+ if (resources != null)
+ eventMessage ??= resources.GetString("event_" + eventName, CultureInfo.InvariantCulture);
Debug.Assert(info!.Attribs != null);
if (info.Attribs.EventChannelType == EventChannelType.Admin && eventMessage == null)
@@ -5976,8 +5940,7 @@ namespace System.Diagnostics.Tracing
return "";
string? ret;
- if (taskTab == null)
- taskTab = new Dictionary<int, string>();
+ taskTab ??= new Dictionary<int, string>();
if (!taskTab.TryGetValue((int)task, out ret))
ret = taskTab[(int)task] = eventName;
return ret;
@@ -6108,8 +6071,7 @@ namespace System.Diagnostics.Tracing
private static void UpdateStringBuilder([NotNull] ref StringBuilder? stringBuilder, string eventMessage, int startIndex, int count)
{
- if (stringBuilder == null)
- stringBuilder = new StringBuilder();
+ stringBuilder ??= new StringBuilder();
stringBuilder.Append(eventMessage, startIndex, count);
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs
index 3ef69b03685..321ae819f50 100644
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs
@@ -37,7 +37,7 @@ namespace System.Diagnostics.Tracing
{
if (IsEnabled())
{
- if (arg3 == null) arg3 = "";
+ arg3 ??= "";
fixed (char* string3Bytes = arg3)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[6];
@@ -70,7 +70,7 @@ namespace System.Diagnostics.Tracing
{
if (IsEnabled())
{
- if (arg3 == null) arg3 = "";
+ arg3 ??= "";
fixed (char* string3Bytes = arg3)
{
EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs
index a34675facac..a5de12342d1 100644
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs
@@ -162,13 +162,12 @@ namespace System.Diagnostics.Tracing
public static TraceLoggingTypeInfo GetInstance(Type type, List<Type>? recursionCheck)
{
- Dictionary<Type, TraceLoggingTypeInfo> cache = threadCache ?? (threadCache = new Dictionary<Type, TraceLoggingTypeInfo>());
+ Dictionary<Type, TraceLoggingTypeInfo> cache = threadCache ??= new Dictionary<Type, TraceLoggingTypeInfo>();
TraceLoggingTypeInfo? instance;
if (!cache.TryGetValue(type, out instance))
{
- if (recursionCheck == null)
- recursionCheck = new List<Type>();
+ recursionCheck ??= new List<Type>();
int recursionCheckCount = recursionCheck.Count;
instance = Statics.CreateDefaultTypeInfo(type, recursionCheck);
cache[type] = instance;
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs
index a230f541ee4..03d86f8efab 100644
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs
@@ -117,7 +117,6 @@ namespace System.Diagnostics.Tracing
/// <summary>
/// EventChannel. Custom values must be in the range from 16 through 255. Currently only predefined values allowed.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1028:EnumStorageShouldBeInt32", Justification = "Backwards compatibility")]
public enum EventChannel : byte
{
/// <summary>
diff --git a/netcore/System.Private.CoreLib/shared/System/Exception.cs b/netcore/System.Private.CoreLib/shared/System/Exception.cs
index 0fe895c2b8b..5e4f0789010 100644
--- a/netcore/System.Private.CoreLib/shared/System/Exception.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Exception.cs
@@ -87,7 +87,7 @@ namespace System
public virtual string? Source
{
- get => _source ?? (_source = CreateSourceName());
+ get => _source ??= CreateSourceName();
set => _source = value;
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs
index 88e47bac81c..997cfb406e4 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs
@@ -112,23 +112,23 @@ namespace System.Globalization
// Something failed, try invariant for missing parts
// This is really not good, but we don't want the callers to crash.
- if (this.sNativeName == null) this.sNativeName = string.Empty; // Calendar Name for the locale.
+ this.sNativeName ??= string.Empty; // Calendar Name for the locale.
// Formats
- if (this.saShortDates == null) this.saShortDates = Invariant.saShortDates; // Short Data format, default first
- if (this.saYearMonths == null) this.saYearMonths = Invariant.saYearMonths; // Year/Month Data format, default first
- if (this.saLongDates == null) this.saLongDates = Invariant.saLongDates; // Long Data format, default first
- if (this.sMonthDay == null) this.sMonthDay = Invariant.sMonthDay; // Month/Day format
+ this.saShortDates ??= Invariant.saShortDates; // Short Data format, default first
+ this.saYearMonths ??= Invariant.saYearMonths; // Year/Month Data format, default first
+ this.saLongDates ??= Invariant.saLongDates; // Long Data format, default first
+ this.sMonthDay ??= Invariant.sMonthDay; // Month/Day format
// Calendar Parts Names
- if (this.saEraNames == null) this.saEraNames = Invariant.saEraNames; // Names of Eras
- if (this.saAbbrevEraNames == null) this.saAbbrevEraNames = Invariant.saAbbrevEraNames; // Abbreviated Era Names
- if (this.saAbbrevEnglishEraNames == null) this.saAbbrevEnglishEraNames = Invariant.saAbbrevEnglishEraNames; // Abbreviated Era Names in English
- if (this.saDayNames == null) this.saDayNames = Invariant.saDayNames; // Day Names, null to use locale data, starts on Sunday
- if (this.saAbbrevDayNames == null) this.saAbbrevDayNames = Invariant.saAbbrevDayNames; // Abbrev Day Names, null to use locale data, starts on Sunday
- if (this.saSuperShortDayNames == null) this.saSuperShortDayNames = Invariant.saSuperShortDayNames; // Super short Day of week names
- if (this.saMonthNames == null) this.saMonthNames = Invariant.saMonthNames; // Month Names (13)
- if (this.saAbbrevMonthNames == null) this.saAbbrevMonthNames = Invariant.saAbbrevMonthNames; // Abbrev Month Names (13)
+ this.saEraNames ??= Invariant.saEraNames; // Names of Eras
+ this.saAbbrevEraNames ??= Invariant.saAbbrevEraNames; // Abbreviated Era Names
+ this.saAbbrevEnglishEraNames ??= Invariant.saAbbrevEnglishEraNames; // Abbreviated Era Names in English
+ this.saDayNames ??= Invariant.saDayNames; // Day Names, null to use locale data, starts on Sunday
+ this.saAbbrevDayNames ??= Invariant.saAbbrevDayNames; // Abbrev Day Names, null to use locale data, starts on Sunday
+ this.saSuperShortDayNames ??= Invariant.saSuperShortDayNames; // Super short Day of week names
+ this.saMonthNames ??= Invariant.saMonthNames; // Month Names (13)
+ this.saAbbrevMonthNames ??= Invariant.saAbbrevMonthNames; // Abbrev Month Names (13)
// Genitive and Leap names can follow the fallback below
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs
index b8cb91b50ac..6c1902c7162 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs
@@ -379,8 +379,7 @@ namespace System.Globalization
{
// Found another ', so we have ''. Need to add \' instead.
// 1st make sure we have our stringbuilder
- if (result == null)
- result = new StringBuilder(str, 0, i, str.Length * 2);
+ result ??= new StringBuilder(str, 0, i, str.Length * 2);
// Append a \' and keep going (so we don't turn off quote mode)
result.Append("\\'");
@@ -402,8 +401,7 @@ namespace System.Globalization
{
// Found a \, need to change it to \\
// 1st make sure we have our stringbuilder
- if (result == null)
- result = new StringBuilder(str, 0, i, str.Length * 2);
+ result ??= new StringBuilder(str, 0, i, str.Length * 2);
// Append our \\ to the string & continue
result.Append("\\\\");
@@ -411,8 +409,7 @@ namespace System.Globalization
}
// If we have a builder we need to add our character
- if (result != null)
- result.Append(str[i]);
+ result?.Append(str[i]);
}
// Unchanged string? , just return input string
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs
index 7963d84d2c2..de6f326b6f3 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs
@@ -1880,10 +1880,7 @@ namespace System.Globalization
int calendarIndex = (int)calendarId - 1;
// Have to have calendars
- if (_calendars == null)
- {
- _calendars = new CalendarData[CalendarData.MAX_CALENDARS];
- }
+ _calendars ??= new CalendarData[CalendarData.MAX_CALENDARS];
// we need the following local variable to avoid returning null
// when another thread creates a new array of CalendarData (above)
@@ -2157,16 +2154,10 @@ namespace System.Globalization
switch (str[i])
{
case '\'':
- if (result == null)
- {
- result = new StringBuilder(str, start, i - start, str.Length);
- }
+ result ??= new StringBuilder(str, start, i - start, str.Length);
break;
case '\\':
- if (result == null)
- {
- result = new StringBuilder(str, start, i - start, str.Length);
- }
+ result ??= new StringBuilder(str, start, i - start, str.Length);
++i;
if (i < str.Length)
{
@@ -2174,10 +2165,7 @@ namespace System.Globalization
}
break;
default:
- if (result != null)
- {
- result.Append(str[i]);
- }
+ result?.Append(str[i]);
break;
}
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs
index 430b1bffb43..33302642924 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs
@@ -150,31 +150,11 @@ namespace System.Globalization
private DateTimeFormatFlags formatFlags = DateTimeFormatFlags.NotInitialized;
- private string CultureName => _name ?? (_name = _cultureData.CultureName);
+ private string CultureName => _name ??= _cultureData.CultureName;
- private CultureInfo Culture
- {
- get
- {
- if (_cultureInfo == null)
- {
- _cultureInfo = CultureInfo.GetCultureInfo(CultureName);
- }
- return _cultureInfo;
- }
- }
+ private CultureInfo Culture => _cultureInfo ??= CultureInfo.GetCultureInfo(CultureName);
- private string LanguageName
- {
- get
- {
- if (_langName == null)
- {
- _langName = _cultureData.TwoLetterISOLanguageName;
- }
- return _langName;
- }
- }
+ private string LanguageName => _langName ??= _cultureData.TwoLetterISOLanguageName;
/// <summary>
/// Create an array of string which contains the abbreviated day names.
@@ -1898,62 +1878,25 @@ namespace System.Globalization
// Decimal separator used by positive TimeSpan pattern
private string? _decimalSeparator;
- internal string DecimalSeparator
- {
- get
- {
- if (_decimalSeparator == null)
- {
- CultureData? cultureDataWithoutUserOverrides = _cultureData.UseUserOverride ?
- CultureData.GetCultureData(_cultureData.CultureName, false) :
- _cultureData;
- _decimalSeparator = new NumberFormatInfo(cultureDataWithoutUserOverrides).NumberDecimalSeparator;
- }
- return _decimalSeparator;
- }
- }
+ internal string DecimalSeparator =>
+ _decimalSeparator ??=
+ new NumberFormatInfo(_cultureData.UseUserOverride ? CultureData.GetCultureData(_cultureData.CultureName, false) : _cultureData).NumberDecimalSeparator;
// Positive TimeSpan Pattern
private string? _fullTimeSpanPositivePattern;
- internal string FullTimeSpanPositivePattern
- {
- get
- {
- if (_fullTimeSpanPositivePattern == null)
- {
- _fullTimeSpanPositivePattern = "d':'h':'mm':'ss'" + DecimalSeparator + "'FFFFFFF";
- }
- return _fullTimeSpanPositivePattern;
- }
- }
+ internal string FullTimeSpanPositivePattern =>
+ _fullTimeSpanPositivePattern ??= "d':'h':'mm':'ss'" + DecimalSeparator + "'FFFFFFF";
// Negative TimeSpan Pattern
private string? _fullTimeSpanNegativePattern;
- internal string FullTimeSpanNegativePattern
- {
- get
- {
- if (_fullTimeSpanNegativePattern == null)
- _fullTimeSpanNegativePattern = "'-'" + FullTimeSpanPositivePattern;
- return _fullTimeSpanNegativePattern;
- }
- }
+ internal string FullTimeSpanNegativePattern =>
+ _fullTimeSpanNegativePattern ??= "'-'" + FullTimeSpanPositivePattern;
// Get suitable CompareInfo from current DTFI object.
- internal CompareInfo CompareInfo
- {
- get
- {
- if (_compareInfo == null)
- {
- // We use the regular GetCompareInfo here to make sure the created CompareInfo object is stored in the
- // CompareInfo cache. otherwise we would just create CompareInfo using _cultureData.
- _compareInfo = CompareInfo.GetCompareInfo(_cultureData.SortName);
- }
-
- return _compareInfo;
- }
- }
+ internal CompareInfo CompareInfo =>
+ // We use the regular GetCompareInfo here to make sure the created CompareInfo object is stored in the
+ // CompareInfo cache. otherwise we would just create CompareInfo using _cultureData.
+ _compareInfo ??= CompareInfo.GetCompareInfo(_cultureData.SortName);
internal const DateTimeStyles InvalidDateTimeStyles = ~(DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite
| DateTimeStyles.AllowInnerWhite | DateTimeStyles.NoCurrentDateDefault
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
index 269d0878601..e93ad3d930c 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
@@ -214,10 +214,8 @@ namespace System.Globalization
if (KnownWords.TryGetValue(str, out _) == false)
{
- if (m_dateWords == null)
- {
- m_dateWords = new List<string>();
- }
+ m_dateWords ??= new List<string>();
+
if (formatPostfix == "MMMM")
{
// Add the word into the ArrayList as "\xfffe" + real month postfix.
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs
index e2f754745d4..dcde531546e 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs
@@ -5896,13 +5896,7 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR,
internal DTSubStringType type;
internal int value;
- internal char this[int relativeIndex]
- {
- get
- {
- return s[index + relativeIndex];
- }
- }
+ internal char this[int relativeIndex] => s[index + relativeIndex];
}
//
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs
index 57a38d5a19a..11c552a82fa 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs
@@ -39,10 +39,7 @@ namespace System.Globalization
/// Internal method to provide a default intance of GregorianCalendar.
/// Used by NLS+ implementation
/// </summary>
- internal static Calendar GetDefaultInstance()
- {
- return s_defaultInstance ?? (s_defaultInstance = new GregorianCalendar());
- }
+ internal static Calendar GetDefaultInstance() => s_defaultInstance ??= new GregorianCalendar();
public GregorianCalendar() : this(GregorianCalendarTypes.Localized)
{
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs
index 3449a84b901..eae8fa0bc87 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs
@@ -84,10 +84,7 @@ namespace System.Globalization
internal static volatile Calendar? s_defaultInstance;
internal GregorianCalendarHelper _helper;
- internal static Calendar GetDefaultInstance()
- {
- return s_defaultInstance ?? (s_defaultInstance = new JapaneseCalendar());
- }
+ internal static Calendar GetDefaultInstance() => s_defaultInstance ??= new JapaneseCalendar();
public JapaneseCalendar()
{
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs
index edd599b5371..03003826dfa 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs
@@ -32,10 +32,7 @@ namespace System.Globalization
private readonly GregorianCalendarHelper _helper;
- internal static Calendar GetDefaultInstance()
- {
- return s_defaultInstance ?? (s_defaultInstance = new TaiwanCalendar());
- }
+ internal static Calendar GetDefaultInstance() => s_defaultInstance ??= new TaiwanCalendar();
private static readonly DateTime s_calendarMinValue = new DateTime(1912, 1, 1);
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs
index 7fe69d66481..4187c0df715 100644
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs
@@ -126,7 +126,7 @@ namespace System.Globalization
/// </summary>
public virtual string ListSeparator
{
- get => _listSeparator ?? (_listSeparator = _cultureData.ListSeparator);
+ get => _listSeparator ??= _cultureData.ListSeparator;
set
{
if (value == null)
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs b/netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs
index c33a7406b78..2b213fe63ca 100644
--- a/netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs
+++ b/netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs
@@ -148,10 +148,7 @@ namespace System.IO
posSav = _stream.Position;
}
- if (_charBytes == null)
- {
- _charBytes = new byte[MaxCharBytesSize];
- }
+ _charBytes ??= new byte[MaxCharBytesSize];
Span<char> singleChar = stackalloc char[1];
@@ -289,15 +286,8 @@ namespace System.IO
return string.Empty;
}
- if (_charBytes == null)
- {
- _charBytes = new byte[MaxCharBytesSize];
- }
-
- if (_charBuffer == null)
- {
- _charBuffer = new char[_maxCharsSize];
- }
+ _charBytes ??= new byte[MaxCharBytesSize];
+ _charBuffer ??= new char[_maxCharsSize];
StringBuilder? sb = null;
do
@@ -409,10 +399,7 @@ namespace System.IO
}
else
{
- if (_charBytes == null)
- {
- _charBytes = new byte[MaxCharBytesSize];
- }
+ _charBytes ??= new byte[MaxCharBytesSize];
if (numBytes > MaxCharBytesSize)
{
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs
index 30f02786ed9..cbecd390c3b 100644
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs
+++ b/netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs
@@ -41,17 +41,7 @@ namespace System.IO
FileName = fileName;
}
- public override string Message
- {
- get
- {
- if (_message == null)
- {
- _message = FormatFileLoadExceptionMessage(FileName, HResult);
- }
- return _message;
- }
- }
+ public override string Message => _message ??= FormatFileLoadExceptionMessage(FileName, HResult);
public string? FileName { get; }
public string? FusionLog { get; }
@@ -71,8 +61,7 @@ namespace System.IO
if (FusionLog != null)
{
- if (s == null)
- s = " ";
+ s ??= " ";
s += Environment.NewLine;
s += Environment.NewLine;
s += FusionLog;
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs
index dd152bec47d..a4d6e442d4e 100644
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs
+++ b/netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs
@@ -85,8 +85,7 @@ namespace System.IO
if (FusionLog != null)
{
- if (s == null)
- s = " ";
+ s ??= " ";
s += Environment.NewLine;
s += Environment.NewLine;
s += FusionLog;
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs
index db2cf4cd191..9de86d1a67d 100644
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs
+++ b/netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs
@@ -77,8 +77,7 @@ namespace System.IO
// Quick check to make sure the IO hasn't completed
if (_overlapped != null)
{
- Action<object?>? cancelCallback = s_cancelCallback;
- if (cancelCallback == null) s_cancelCallback = cancelCallback = Cancel;
+ Action<object?>? cancelCallback = s_cancelCallback ??= Cancel;
// Register the cancellation only if the IO hasn't completed
long packedResult = Interlocked.CompareExchange(ref _result, RegisteringCancellation, NoResult);
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Stream.cs b/netcore/System.Private.CoreLib/shared/System/IO/Stream.cs
index e53fc9f8ad6..f9e2ecb4698 100644
--- a/netcore/System.Private.CoreLib/shared/System/IO/Stream.cs
+++ b/netcore/System.Private.CoreLib/shared/System/IO/Stream.cs
@@ -645,8 +645,7 @@ namespace System.IO
{
_context = null;
- ContextCallback? invokeAsyncCallback = s_invokeAsyncCallback;
- if (invokeAsyncCallback == null) s_invokeAsyncCallback = invokeAsyncCallback = InvokeAsyncCallback; // benign race condition
+ ContextCallback? invokeAsyncCallback = s_invokeAsyncCallback ??= InvokeAsyncCallback;
ExecutionContext.RunInternal(context, invokeAsyncCallback, this);
}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs b/netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs
index 9db4769817b..3fdfe77ae6e 100644
--- a/netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs
+++ b/netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs
@@ -812,11 +812,9 @@ namespace System.IO
}
i++;
} while (i < _charLen);
+
i = _charLen - _charPos;
- if (sb == null)
- {
- sb = new StringBuilder(i + 80);
- }
+ sb ??= new StringBuilder(i + 80);
sb.Append(_charBuffer, _charPos, i);
} while (ReadBuffer() > 0);
return sb.ToString();
@@ -896,10 +894,7 @@ namespace System.IO
} while (i < tmpCharLen);
i = tmpCharLen - tmpCharPos;
- if (sb == null)
- {
- sb = new StringBuilder(i + 80);
- }
+ sb ??= new StringBuilder(i + 80);
sb.Append(tmpCharBuffer, tmpCharPos, i);
} while (await ReadBufferAsync().ConfigureAwait(false) > 0);
@@ -1330,7 +1325,6 @@ namespace System.IO
return -1;
}
- [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override int Read(char[] buffer, int index, int count)
{
return 0;
diff --git a/netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs b/netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs
index 64648784581..592b8171d90 100644
--- a/netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs
+++ b/netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace System
@@ -16,7 +17,7 @@ namespace System
internal ThreadLocal<object?> Data { get; private set; }
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA1821", Justification = "Finalizer preserved for compat, it is suppressed by the constructor.")]
+ [SuppressMessage("Microsoft.Security", "CA1821", Justification = "Finalizer preserved for compat, it is suppressed by the constructor.")]
~LocalDataStoreSlot()
{
}
diff --git a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs b/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs
index 801c87fa490..a0286dc9864 100644
--- a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs
+++ b/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs
@@ -227,8 +227,7 @@ namespace System
if (source.Overlaps(destination))
throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
- if (culture == null)
- culture = CultureInfo.CurrentCulture;
+ culture ??= CultureInfo.CurrentCulture;
// Assuming that changing case does not affect length
if (destination.Length < source.Length)
@@ -280,8 +279,7 @@ namespace System
if (source.Overlaps(destination))
throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
- if (culture == null)
- culture = CultureInfo.CurrentCulture;
+ culture ??= CultureInfo.CurrentCulture;
// Assuming that changing case does not affect length
if (destination.Length < source.Length)
diff --git a/netcore/System.Private.CoreLib/shared/System/Object.cs b/netcore/System.Private.CoreLib/shared/System/Object.cs
index 376bb5536f9..a8e12bc18d0 100644
--- a/netcore/System.Private.CoreLib/shared/System/Object.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Object.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
@@ -28,7 +29,7 @@ namespace System
// Allow an object to free resources before the object is reclaimed by the GC.
// This method's virtual slot number is hardcoded in runtimes. Do not add any virtual methods ahead of this.
[NonVersionable]
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1821:RemoveEmptyFinalizers")]
+ [SuppressMessage("Microsoft.Performance", "CA1821:RemoveEmptyFinalizers")]
~Object()
{
}
diff --git a/netcore/System.Private.CoreLib/shared/System/ParamsArray.cs b/netcore/System.Private.CoreLib/shared/System/ParamsArray.cs
index 88277b3376d..9ab86fa5167 100644
--- a/netcore/System.Private.CoreLib/shared/System/ParamsArray.cs
+++ b/netcore/System.Private.CoreLib/shared/System/ParamsArray.cs
@@ -62,10 +62,7 @@ namespace System
public int Length => _args.Length;
- public object? this[int index]
- {
- get { return index == 0 ? _arg0 : GetAtSlow(index); }
- }
+ public object? this[int index] => index == 0 ? _arg0 : GetAtSlow(index);
private object? GetAtSlow(int index)
{
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs
index 690c3b0fae8..32e9a074cb4 100644
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs
@@ -165,12 +165,7 @@ namespace System.Reflection
// The compressed version of the public key formed from a truncated hash.
// Will throw a SecurityException if _publicKey is invalid
- public byte[]? GetPublicKeyToken()
- {
- if (_publicKeyToken == null)
- _publicKeyToken = ComputePublicKeyToken();
- return _publicKeyToken;
- }
+ public byte[]? GetPublicKeyToken() => _publicKeyToken ??= ComputePublicKeyToken();
public void SetPublicKeyToken(byte[]? publicKeyToken)
{
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs
index be4d7dd4edf..4c229820f55 100644
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs
@@ -154,8 +154,7 @@ namespace System.Resources
// an empty string. We may in fact fail earlier for another reason, but otherwise we will
// throw a MissingManifestResourceException when GetString is called indicating that a
// resW filename called "" could not be found.
- if (reswFilename == null)
- reswFilename = string.Empty;
+ reswFilename ??= string.Empty;
// At this point it is important NOT to set _useUapResourceManagement to false
// if the PRI file does not exist because we are now certain we need to load PRI
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs
index 7f486b39993..8d98b575b8e 100644
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs
@@ -608,10 +608,7 @@ namespace System.Resources
}
#endif
- if (culture == null)
- {
- culture = CultureInfo.CurrentUICulture;
- }
+ culture ??= CultureInfo.CurrentUICulture;
ResourceSet? last = GetFirstResourceSet(culture);
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs b/netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs
index 2a9e2c548aa..76d1d4aac2b 100644
--- a/netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs
@@ -370,9 +370,9 @@ namespace System.Resources
if (!_haveReadFromReader)
{
// If necessary, init our case insensitive hash table.
- if (ignoreCase && _caseInsensitiveTable == null)
+ if (ignoreCase)
{
- _caseInsensitiveTable = new Dictionary<string, ResourceLocator>(StringComparer.OrdinalIgnoreCase);
+ _caseInsensitiveTable ??= new Dictionary<string, ResourceLocator>(StringComparer.OrdinalIgnoreCase);
}
if (_defaultReader == null)
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs
index f75ca12ef06..5adf4471e8f 100644
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs
@@ -61,7 +61,7 @@ namespace System.Runtime.CompilerServices
if (eventArgs.Unwind)
{
// unwind
- if (innerException == null) { innerException = eventArgs.thrownDuringHandler; }
+ innerException ??= eventArgs.thrownDuringHandler;
throw new ContractException(failureKind, displayMessage, userMessage, conditionText, innerException);
}
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs
index 02a21c37e71..bdee5189b3c 100644
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs
@@ -16,7 +16,6 @@ namespace System.Runtime.CompilerServices
/// Gets the strongly typed value associated with the <see cref = "StrongBox{T}"></see>
/// <remarks>This is explicitly exposed as a field instead of a property to enable loading the address of the field.</remarks>
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
[MaybeNull] public T Value = default!;
/// <summary>
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs
index 0f22b036328..a6e07b8e53d 100644
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs
@@ -12,6 +12,8 @@
**
===========================================================*/
+using System.Diagnostics.CodeAnalysis;
+
namespace System.Runtime.ConstrainedExecution
{
public abstract class CriticalFinalizerObject
@@ -20,7 +22,7 @@ namespace System.Runtime.ConstrainedExecution
{
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1821:RemoveEmptyFinalizers")]
+ [SuppressMessage("Microsoft.Performance", "CA1821:RemoveEmptyFinalizers")]
~CriticalFinalizerObject()
{
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs
index 234446ce480..c9f8766aecb 100644
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs
@@ -23,7 +23,6 @@ namespace System.Runtime.InteropServices
// manipulating _state.
/// <summary>Specifies the handle to be wrapped.</summary>
- [SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
protected IntPtr handle;
/// <summary>Combined ref count and closed/disposed flags (so we can atomically modify them).</summary>
private volatile int _state;
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs
index 83c27fb9236..200a4becfde 100644
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs
@@ -34,15 +34,8 @@ namespace System.Runtime.Serialization
[ThreadStatic]
private static DeserializationTracker? t_deserializationTracker;
- private static DeserializationTracker GetThreadDeserializationTracker()
- {
- if (t_deserializationTracker == null)
- {
- t_deserializationTracker = new DeserializationTracker();
- }
-
- return t_deserializationTracker;
- }
+ private static DeserializationTracker GetThreadDeserializationTracker() =>
+ t_deserializationTracker ??= new DeserializationTracker();
#endif // !CORECLR
// Returns true if deserialization is currently in progress
diff --git a/netcore/System.Private.CoreLib/shared/System/RuntimeType.cs b/netcore/System.Private.CoreLib/shared/System/RuntimeType.cs
index 81cb7e7a03e..70cd615887f 100644
--- a/netcore/System.Private.CoreLib/shared/System/RuntimeType.cs
+++ b/netcore/System.Private.CoreLib/shared/System/RuntimeType.cs
@@ -82,10 +82,7 @@ namespace System
members = GetMember(defaultMemberName);
}
- if (members == null)
- members = Array.Empty<MemberInfo>();
-
- return members;
+ return members ?? Array.Empty<MemberInfo>();
}
public override Type GetElementType() => RuntimeTypeHandle.GetElementType(this);
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs
index 93d505615b1..3ebf72411f1 100644
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs
@@ -245,8 +245,7 @@ namespace System.Security
if (child == null)
throw new ArgumentNullException(nameof(child));
- if (_children == null)
- _children = new ArrayList(ChildrenTypical);
+ _children ??= new ArrayList(ChildrenTypical);
_children.Add(child);
}
@@ -405,8 +404,7 @@ namespace System.Security
}
else
{
- if (sb == null)
- sb = new StringBuilder();
+ sb ??= new StringBuilder();
sb.Append(str, newIndex, index - newIndex);
sb.Append(GetEscapeSequence(str[index]));
@@ -470,8 +468,7 @@ namespace System.Security
}
else
{
- if (sb == null)
- sb = new StringBuilder();
+ sb ??= new StringBuilder();
sb.Append(str, newIndex, index - newIndex);
sb.Append(GetUnescapeSequence(str, index, out newIndex)); // updates the newIndex too
diff --git a/netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs b/netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs
index 7944df5968f..0c79ce37c14 100644
--- a/netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs
+++ b/netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs
@@ -1000,8 +1000,7 @@ namespace System
// If they asked to replace oldValue with a null, replace all occurrences
// with the empty string.
- if (newValue == null)
- newValue = string.Empty;
+ newValue ??= string.Empty;
CultureInfo referenceCulture = culture ?? CultureInfo.CurrentCulture;
StringBuilder result = StringBuilderCache.Acquire();
@@ -1119,8 +1118,7 @@ namespace System
throw new ArgumentException(SR.Argument_StringZeroLength, nameof(oldValue));
// Api behavior: if newValue is null, instances of oldValue are to be removed.
- if (newValue == null)
- newValue = string.Empty;
+ newValue ??= string.Empty;
Span<int> initialSpan = stackalloc int[StackallocIntBufferSizeLimit];
var replacementIndices = new ValueListBuilder<int>(initialSpan);
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs
index 7991419f698..ad47a58067d 100644
--- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs
@@ -71,8 +71,7 @@ namespace System.Text
lock (InternalSyncObject)
{
// Double check before we do it again.
- if (_oFallback._arrayBestFit == null)
- _oFallback._arrayBestFit = fallback._encoding.GetBestFitBytesToUnicodeData();
+ _oFallback._arrayBestFit ??= fallback._encoding.GetBestFitBytesToUnicodeData();
}
}
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs
index 33df140e670..d3b24e1d91a 100644
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs
@@ -71,8 +71,7 @@ namespace System.Text
lock (InternalSyncObject)
{
// Double check before we do it again.
- if (_oFallback._arrayBestFit == null)
- _oFallback._arrayBestFit = fallback._encoding.GetBestFitUnicodeToBytesData();
+ _oFallback._arrayBestFit ??= fallback._encoding.GetBestFitUnicodeToBytesData();
}
}
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
index 1300f16c360..becf7e12e99 100644
--- a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
@@ -1781,9 +1781,9 @@ namespace System.Text
// Otherwise, fallback to trying IFormattable or calling ToString.
if (arg is IFormattable formattableArg)
{
- if (itemFormatSpan.Length != 0 && itemFormat == null)
+ if (itemFormatSpan.Length != 0)
{
- itemFormat = new string(itemFormatSpan);
+ itemFormat ??= new string(itemFormatSpan);
}
s = formattableArg.ToString(itemFormat, provider);
}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs
index dec0eab801a..1ed5c02be63 100644
--- a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs
@@ -697,7 +697,7 @@ namespace System.Threading
catch (Exception ex) when (!throwOnFirstException)
{
// Store the exception and continue
- (exceptionList ?? (exceptionList = new List<Exception>())).Add(ex);
+ (exceptionList ??= new List<Exception>()).Add(ex);
}
// Drop the node. While we could add it to the free list, doing so has cost (we'd need to take the lock again)
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs
index dd8a36ebe2b..abbdc13c9de 100644
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs
@@ -226,7 +226,7 @@ namespace System.Threading.Tasks
// Store the faulted task's exceptions
CompletionState cs = EnsureCompletionStateInitialized();
- if (cs.m_exceptions == null) cs.m_exceptions = new List<Exception>();
+ cs.m_exceptions ??= new List<Exception>();
cs.m_exceptions.AddRange(faultedTask.Exception.InnerExceptions);
// Now that we're doomed, request completion
@@ -246,20 +246,15 @@ namespace System.Threading.Tasks
/// <summary>Gets the number of tasks waiting to run concurrently.</summary>
/// <remarks>This does not take the necessary lock, as it's only called from under the debugger.</remarks>
- [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
private int ConcurrentTaskCountForDebugger => m_concurrentTaskScheduler.m_tasks.Count;
/// <summary>Gets the number of tasks waiting to run exclusively.</summary>
/// <remarks>This does not take the necessary lock, as it's only called from under the debugger.</remarks>
- [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
private int ExclusiveTaskCountForDebugger => m_exclusiveTaskScheduler.m_tasks.Count;
/// <summary>Notifies the pair that new work has arrived to be processed.</summary>
/// <param name="fairly">Whether tasks should be scheduled fairly with regards to other tasks.</param>
/// <remarks>Must only be called while holding the lock.</remarks>
- [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
- [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals")]
- [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
private void ProcessAsyncIfNecessary(bool fairly = false)
{
ContractAssertMonitorStatus(ValueLock, held: true);
@@ -344,7 +339,7 @@ namespace System.Threading.Tasks
{
if (TaskScheduler.Default == m_underlyingTaskScheduler)
{
- IThreadPoolWorkItem workItem = m_threadPoolWorkItem ?? (m_threadPoolWorkItem = new SchedulerWorkItem(this));
+ IThreadPoolWorkItem workItem = m_threadPoolWorkItem ??= new SchedulerWorkItem(this);
ThreadPool.UnsafeQueueUserWorkItemInternal(workItem, preferLocal: !fairly);
return true;
}
@@ -467,7 +462,6 @@ namespace System.Threading.Tasks
/// state in one of those conditions or if the user explicitly asks for
/// the Completion.
/// </summary>
- [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
private sealed class CompletionState : Task
{
/// <summary>Whether the scheduler has had completion requested.</summary>
@@ -622,7 +616,6 @@ namespace System.Threading.Tasks
/// </summary>
/// <param name="task">The task to execute inline if possible.</param>
/// <returns>true if the task was inlined successfully; otherwise, false.</returns>
- [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "ignored")]
private bool TryExecuteTaskInlineOnTargetScheduler(Task task)
{
// We'd like to simply call TryExecuteTaskInline here, but we can't.
@@ -669,7 +662,6 @@ namespace System.Threading.Tasks
protected override IEnumerable<Task> GetScheduledTasks() { return m_tasks; }
/// <summary>Gets the number of tasks queued to this scheduler.</summary>
- [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
private int CountForDebugger => m_tasks.Count;
/// <summary>Provides a debug view for ConcurrentExclusiveTaskScheduler.</summary>
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs
index 8b6632c9ee9..1cd12545156 100644
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs
@@ -1333,10 +1333,8 @@ namespace System.Threading.Tasks
/// ASSUMES THAT m_stateFlags IS ALREADY SET!
/// </summary>
/// <returns>The initialized contingent properties object.</returns>
- internal ContingentProperties EnsureContingentPropertiesInitializedUnsafe()
- {
- return m_contingentProperties ?? (m_contingentProperties = new ContingentProperties());
- }
+ internal ContingentProperties EnsureContingentPropertiesInitializedUnsafe() =>
+ m_contingentProperties ??= new ContingentProperties();
/// <summary>
/// This internal property provides access to the CancellationToken that was set on the task
@@ -4777,7 +4775,7 @@ namespace System.Threading.Tasks
/// <param name="initSize">The size to which to initialize the list if the list is null.</param>
private static void AddToList<T>(T item, ref List<T>? list, int initSize)
{
- if (list == null) list = new List<T>(initSize);
+ list ??= new List<T>(initSize);
list.Add(item);
}
@@ -4863,11 +4861,7 @@ namespace System.Threading.Tasks
// this will make sure it won't throw again in the implicit wait
t.UpdateExceptionObservedStatus();
- if (exceptions == null)
- {
- exceptions = new List<Exception>(ex.InnerExceptions.Count);
- }
-
+ exceptions ??= new List<Exception>(ex.InnerExceptions.Count);
exceptions.AddRange(ex.InnerExceptions);
}
}
@@ -5690,12 +5684,12 @@ namespace System.Threading.Tasks
if (task.IsFaulted)
{
- if (observedExceptions == null) observedExceptions = new List<ExceptionDispatchInfo>();
+ observedExceptions ??= new List<ExceptionDispatchInfo>();
observedExceptions.AddRange(task.GetExceptionDispatchInfos());
}
else if (task.IsCanceled)
{
- if (canceledTask == null) canceledTask = task; // use the first task that's canceled
+ canceledTask ??= task; // use the first task that's canceled
}
// Regardless of completion state, if the task has its debug bit set, transfer it to the
@@ -5924,12 +5918,12 @@ namespace System.Threading.Tasks
if (task.IsFaulted)
{
- if (observedExceptions == null) observedExceptions = new List<ExceptionDispatchInfo>();
+ observedExceptions ??= new List<ExceptionDispatchInfo>();
observedExceptions.AddRange(task.GetExceptionDispatchInfos());
}
else if (task.IsCanceled)
{
- if (canceledTask == null) canceledTask = task; // use the first task that's canceled
+ canceledTask ??= task; // use the first task that's canceled
}
else
{
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs
index 985357731a8..684d2bf4857 100644
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs
@@ -437,12 +437,7 @@ namespace System.Threading.Tasks
/// to be passed as state.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static ContextCallback GetPostActionCallback()
- {
- ContextCallback? callback = s_postActionCallback;
- if (callback == null) { s_postActionCallback = callback = PostAction; } // lazily initialize SecurityCritical delegate
- return callback;
- }
+ private static ContextCallback GetPostActionCallback() => s_postActionCallback ??= PostAction;
}
/// <summary>Task continuation for awaiting with a task scheduler.</summary>
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs
index 8ab07b7774d..8f99a522be4 100644
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs
@@ -212,7 +212,6 @@ namespace System.Threading
}
}
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")]
public bool LocalFindAndPop(object obj)
{
// Fast path: check the tail. If equal, we can skip the lock.
@@ -271,7 +270,6 @@ namespace System.Threading
public object? LocalPop() => m_headIndex < m_tailIndex ? LocalPopCore() : null;
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")]
private object? LocalPopCore()
{
while (true)
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs b/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs
index 587eaca77af..2e47b71aa01 100644
--- a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs
@@ -33,10 +33,7 @@ namespace System.Threading
Debug.Assert(s_scheduledTimers == null);
var timers = new List<TimerQueue>(Instances.Length);
- if (s_scheduledTimersToFire == null)
- {
- s_scheduledTimersToFire = new List<TimerQueue>(Instances.Length);
- }
+ s_scheduledTimersToFire ??= new List<TimerQueue>(Instances.Length);
Thread timerThread = new Thread(TimerThread);
timerThread.IsBackground = true;
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZone.cs b/netcore/System.Private.CoreLib/shared/System/TimeZone.cs
index c9b0c3272d8..c58f3259e38 100644
--- a/netcore/System.Private.CoreLib/shared/System/TimeZone.cs
+++ b/netcore/System.Private.CoreLib/shared/System/TimeZone.cs
@@ -59,14 +59,12 @@ namespace System
{
lock (InternalSyncObject)
{
- if (currentTimeZone == null)
- {
- currentTimeZone = new CurrentSystemTimeZone();
- }
+ currentTimeZone ??= new CurrentSystemTimeZone();
tz = currentTimeZone;
}
}
- return (tz);
+
+ return tz;
}
}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
index 1321fe768ec..584db1d7445 100644
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
+++ b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
@@ -488,10 +488,7 @@ namespace System
// we're returning directories.
if (isDir)
{
- if (toExplore == null)
- {
- toExplore = new List<string>();
- }
+ toExplore ??= new List<string>();
toExplore.Add(fullPath);
}
else if (condition(fullPath))
diff --git a/netcore/System.Private.CoreLib/shared/System/Tuple.cs b/netcore/System.Private.CoreLib/shared/System/Tuple.cs
index 8ef95d2f673..17d9fd98752 100644
--- a/netcore/System.Private.CoreLib/shared/System/Tuple.cs
+++ b/netcore/System.Private.CoreLib/shared/System/Tuple.cs
@@ -292,18 +292,13 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
[Serializable]
@@ -409,19 +404,14 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
[Serializable]
@@ -536,20 +526,15 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
[Serializable]
@@ -673,21 +658,16 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ 4 => Item5,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
[Serializable]
@@ -820,22 +800,17 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ 4 => Item5,
+ 5 => Item6,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
[Serializable]
@@ -977,23 +952,18 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ 4 => Item5,
+ 5 => Item6,
+ 6 => Item7,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
[Serializable]
@@ -1171,23 +1141,18 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
-
- _ => ((ITupleInternal)Rest)[index - 7],
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ 4 => Item5,
+ 5 => Item6,
+ 6 => Item7,
+
+ _ => ((ITupleInternal)Rest)[index - 7],
+ };
}
}
diff --git a/netcore/System.Private.CoreLib/shared/System/ValueTuple.cs b/netcore/System.Private.CoreLib/shared/System/ValueTuple.cs
index 749d172f503..9792b840a80 100644
--- a/netcore/System.Private.CoreLib/shared/System/ValueTuple.cs
+++ b/netcore/System.Private.CoreLib/shared/System/ValueTuple.cs
@@ -137,13 +137,7 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
- {
- throw new IndexOutOfRangeException();
- }
- }
+ object? ITuple.this[int index] => throw new IndexOutOfRangeException();
/// <summary>Creates a new struct 0-tuple.</summary>
/// <returns>A 0-tuple.</returns>
@@ -654,18 +648,13 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
/// <summary>
@@ -857,19 +846,14 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
/// <summary>
@@ -1078,20 +1062,15 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
/// <summary>
@@ -1317,21 +1296,16 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ 4 => Item5,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
/// <summary>
@@ -1574,22 +1548,17 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ 4 => Item5,
+ 5 => Item6,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
/// <summary>
@@ -1849,23 +1818,18 @@ namespace System
/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
- object? ITuple.this[int index]
- {
- get
+ object? ITuple.this[int index] =>
+ index switch
{
- return index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
- _ => throw new IndexOutOfRangeException(),
- };
- }
- }
+ 0 => Item1,
+ 1 => Item2,
+ 2 => Item3,
+ 3 => Item4,
+ 4 => Item5,
+ 5 => Item6,
+ 6 => Item7,
+ _ => throw new IndexOutOfRangeException(),
+ };
}
/// <summary>