diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset
index 3639854c0ed424..e18275f097c78d 100644
--- a/eng/CodeAnalysis.ruleset
+++ b/eng/CodeAnalysis.ruleset
@@ -78,7 +78,7 @@
-
+
diff --git a/src/libraries/Common/src/System/Net/LazyAsyncResult.cs b/src/libraries/Common/src/System/Net/LazyAsyncResult.cs
index 5c2ceb3c4ea803..83648b209d2968 100644
--- a/src/libraries/Common/src/System/Net/LazyAsyncResult.cs
+++ b/src/libraries/Common/src/System/Net/LazyAsyncResult.cs
@@ -41,7 +41,6 @@ private class ThreadContext
}
#if DEBUG
- internal object? _debugAsyncChain = null; // Optionally used to track chains of async calls.
private bool _protectState; // Used by ContextAwareResult to prevent some calls.
#endif
diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs
index f65111e5b6efdc..f94ec12097ac13 100644
--- a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs
+++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs
@@ -14,9 +14,6 @@ internal class ConsoleLogger : ILogger
private static readonly string _messagePadding = new string(' ', GetLogLevelString(LogLevel.Information).Length + LoglevelPadding.Length);
private static readonly string _newLineWithMessagePadding = Environment.NewLine + _messagePadding;
- // ConsoleColor does not have a value to specify the 'Default' color
- private readonly ConsoleColor? DefaultConsoleColor = null;
-
private readonly string _name;
private readonly ConsoleLoggerProcessor _queueProcessor;
@@ -145,7 +142,7 @@ private LogMessageEntry CreateDefaultLogMessage(StringBuilder logBuilder, LogLev
levelString: logLevelString,
levelBackground: logLevelColors.Background,
levelForeground: logLevelColors.Foreground,
- messageColor: DefaultConsoleColor,
+ messageColor: null,
logAsError: logLevel >= Options.LogToStandardErrorThreshold
);
}
@@ -267,30 +264,28 @@ private static string GetSyslogSeverityString(LogLevel logLevel)
private ConsoleColors GetLogLevelConsoleColors(LogLevel logLevel)
{
- if (Options.DisableColors)
+ if (!Options.DisableColors)
{
- return new ConsoleColors(null, null);
+ // We must explicitly set the background color if we are setting the foreground color,
+ // since just setting one can look bad on the users console.
+ switch (logLevel)
+ {
+ case LogLevel.Critical:
+ return new ConsoleColors(ConsoleColor.White, ConsoleColor.Red);
+ case LogLevel.Error:
+ return new ConsoleColors(ConsoleColor.Black, ConsoleColor.Red);
+ case LogLevel.Warning:
+ return new ConsoleColors(ConsoleColor.Yellow, ConsoleColor.Black);
+ case LogLevel.Information:
+ return new ConsoleColors(ConsoleColor.DarkGreen, ConsoleColor.Black);
+ case LogLevel.Debug:
+ return new ConsoleColors(ConsoleColor.Gray, ConsoleColor.Black);
+ case LogLevel.Trace:
+ return new ConsoleColors(ConsoleColor.Gray, ConsoleColor.Black);
+ }
}
- // We must explicitly set the background color if we are setting the foreground color,
- // since just setting one can look bad on the users console.
- switch (logLevel)
- {
- case LogLevel.Critical:
- return new ConsoleColors(ConsoleColor.White, ConsoleColor.Red);
- case LogLevel.Error:
- return new ConsoleColors(ConsoleColor.Black, ConsoleColor.Red);
- case LogLevel.Warning:
- return new ConsoleColors(ConsoleColor.Yellow, ConsoleColor.Black);
- case LogLevel.Information:
- return new ConsoleColors(ConsoleColor.DarkGreen, ConsoleColor.Black);
- case LogLevel.Debug:
- return new ConsoleColors(ConsoleColor.Gray, ConsoleColor.Black);
- case LogLevel.Trace:
- return new ConsoleColors(ConsoleColor.Gray, ConsoleColor.Black);
- default:
- return new ConsoleColors(DefaultConsoleColor, DefaultConsoleColor);
- }
+ return new ConsoleColors(null, null);
}
private void GetScopeInformation(StringBuilder stringBuilder, bool multiLine)
diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Utils.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Utils.cs
index 356bbd3fcbef1d..f344e122007f46 100644
--- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Utils.cs
+++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Utils.cs
@@ -15,6 +15,7 @@ internal static class Utils
public static readonly object BoxedInt2 = 2;
public static readonly object BoxedInt3 = 3;
+#pragma warning disable CA1805 // TODO: https://github.com/dotnet/roslyn-analyzers/pull/3785
public static readonly object BoxedDefaultSByte = default(sbyte);
public static readonly object BoxedDefaultChar = default(char);
public static readonly object BoxedDefaultInt16 = default(short);
@@ -27,6 +28,7 @@ internal static class Utils
public static readonly object BoxedDefaultDouble = default(double);
public static readonly object BoxedDefaultDecimal = default(decimal);
public static readonly object BoxedDefaultDateTime = default(DateTime);
+#pragma warning restore CA1805
private static readonly ConstantExpression s_true = Expression.Constant(BoxedTrue);
private static readonly ConstantExpression s_false = Expression.Constant(BoxedFalse);
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
index bffbe38568d702..60fd39f32af6a7 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
@@ -22,7 +22,7 @@ public partial class HttpClientHandler : HttpMessageHandler
private readonly DiagnosticsHandler _diagnosticsHandler;
private ClientCertificateOption _clientCertificateOptions;
- private volatile bool _disposed = false;
+ private volatile bool _disposed;
public HttpClientHandler()
{
diff --git a/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs b/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
index 72e9425ce812ab..5926278c4caa54 100644
--- a/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
+++ b/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
@@ -68,9 +68,10 @@ public sealed class Cookie
private string m_domainKey = string.Empty; // Do not rename (binary serialization)
- internal bool IsQuotedVersion = false;
-
- internal bool IsQuotedDomain = false;
+#pragma warning disable 0649 // set via reflection by CookieParser: https://github.com/dotnet/runtime/issues/19348
+ internal bool IsQuotedVersion; // Do not rename (binary serialization)
+ internal bool IsQuotedDomain; // Do not rename (binary serialization)
+#pragma warning restore 0649
#if DEBUG
static Cookie()
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/XplatEventLogger.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/XplatEventLogger.cs
index f027781f4fac15..7d00e6defcf37d 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/XplatEventLogger.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/XplatEventLogger.cs
@@ -17,12 +17,12 @@ namespace System.Diagnostics.Tracing
{
internal class XplatEventLogger : EventListener
{
- private static Lazy eventSourceNameFilter = new Lazy(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter"));
- private static Lazy eventSourceEventFilter = new Lazy(() => CompatibilitySwitch.GetValueInternal("EventNameFilter"));
+ private static readonly Lazy eventSourceNameFilter = new Lazy(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter"));
+ private static readonly Lazy eventSourceEventFilter = new Lazy(() => CompatibilitySwitch.GetValueInternal("EventNameFilter"));
public XplatEventLogger() {}
- private static bool initializedPersistentListener = false;
+ private static bool initializedPersistentListener;
public static EventListener? InitializePersistentListener()
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs
index 377dc033f459f0..4eb1b1f94e33be 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs
@@ -89,8 +89,8 @@ private struct LogEntry
private readonly Random _randomIntervalGenerator = new Random();
private readonly LogEntry[] _log = new LogEntry[LogCapacity];
- private int _logStart = 0;
- private int _logSize = 0;
+ private int _logStart;
+ private int _logSize;
public HillClimbing(int wavePeriod, int maxWaveMagnitude, double waveMagnitudeMultiplier, int waveHistorySize, double targetThroughputRatio,
double targetSignalToNoiseRatio, double maxChangePerSecond, double maxChangePerSample, int sampleIntervalMsLow, int sampleIntervalMsHigh,
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs
index 5d1558e3f59e54..364921d06fefb9 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs
@@ -151,7 +151,7 @@ public CompletedWaitHandle(RegisteredWaitHandle completedHandle, bool timedOut)
///
/// The number of user-registered waits on this wait thread.
///
- private int _numUserWaits = 0;
+ private int _numUserWaits;
///
/// A list of removals of wait handles that are waiting for the wait thread to process.
@@ -160,7 +160,7 @@ public CompletedWaitHandle(RegisteredWaitHandle completedHandle, bool timedOut)
///
/// The number of pending removals.
///
- private int _numPendingRemoves = 0;
+ private int _numPendingRemoves;
///
/// An event to notify the wait thread that there are pending adds or removals of wait handles so it needs to wake up.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs
index 25f43493867721..aacaf46f04f922 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs
@@ -28,7 +28,7 @@ internal sealed partial class PortableThreadPool
private const int CpuUtilizationHigh = 95;
private const int CpuUtilizationLow = 80;
- private int _cpuUtilization = 0;
+ private int _cpuUtilization;
private static readonly short s_forcedMinWorkerThreads = AppContextConfigHelper.GetInt16Config("System.Threading.ThreadPool.MinThreads", 0, false);
private static readonly short s_forcedMaxWorkerThreads = AppContextConfigHelper.GetInt16Config("System.Threading.ThreadPool.MaxThreads", 0, false);
@@ -64,7 +64,7 @@ private struct CacheLineSeparated
private readonly LowLevelLock _hillClimbingThreadAdjustmentLock = new LowLevelLock();
- private volatile int _numRequestedWorkers = 0;
+ private volatile int _numRequestedWorkers;
private PortableThreadPool()
{
diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryArray.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryArray.cs
index f36cfc47ae9443..1db788f5b61ca3 100644
--- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryArray.cs
+++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryArray.cs
@@ -14,7 +14,7 @@ internal sealed class BinaryArray : IStreamable
internal int[]? _lowerBoundA;
internal BinaryTypeEnum _binaryTypeEnum;
internal object? _typeInformation;
- internal int _assemId = 0;
+ internal int _assemId;
private BinaryHeaderEnum _binaryHeaderEnum;
internal BinaryArrayTypeEnum _binaryArrayTypeEnum;
diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatter.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatter.cs
index 97fa3a62ff91d0..b601aa1d3238f6 100644
--- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatter.cs
+++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatter.cs
@@ -19,7 +19,7 @@ public sealed class BinaryFormatter : IFormatter
internal FormatterTypeStyle _typeFormat = FormatterTypeStyle.TypesAlways; // For version resiliency, always put out types
internal FormatterAssemblyStyle _assemblyFormat = FormatterAssemblyStyle.Simple;
internal TypeFilterLevel _securityLevel = TypeFilterLevel.Full;
- internal object[]? _crossAppDomainArray = null;
+ internal object[]? _crossAppDomainArray;
public FormatterTypeStyle TypeFormat { get { return _typeFormat; } set { _typeFormat = value; } }
public FormatterAssemblyStyle AssemblyFormat { get { return _assemblyFormat; } set { _assemblyFormat = value; } }
diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterWriter.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterWriter.cs
index c70a3a81d6be24..858aa2cacacdb1 100644
--- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterWriter.cs
+++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterWriter.cs
@@ -21,7 +21,7 @@ internal sealed class BinaryFormatterWriter
private readonly ObjectWriter _objectWriter;
private readonly BinaryWriter _dataWriter;
- private int _consecutiveNullArrayEntryCount = 0;
+ private int _consecutiveNullArrayEntryCount;
private Dictionary? _objectMapTable;
private BinaryObject? _binaryObject;
@@ -29,7 +29,7 @@ internal sealed class BinaryFormatterWriter
private BinaryObjectWithMapTyped? _binaryObjectWithMapTyped;
private BinaryObjectString? _binaryObjectString;
private BinaryArray? _binaryArray;
- private byte[]? _byteBuffer = null;
+ private byte[]? _byteBuffer;
private MemberPrimitiveUnTyped? _memberPrimitiveUnTyped;
private MemberPrimitiveTyped? _memberPrimitiveTyped;
private ObjectNull? _objectNull;
diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs
index dd71d5e69c7455..5a3a5d198c200d 100644
--- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs
+++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs
@@ -18,17 +18,17 @@ internal sealed class WriteObjectInfo
internal object? _obj;
internal Type? _objectType;
- internal bool _isSi = false;
- internal bool _isNamed = false;
- internal bool _isArray = false;
+ internal bool _isSi;
+ internal bool _isNamed;
+ internal bool _isArray;
- internal SerializationInfo? _si = null;
+ internal SerializationInfo? _si;
internal SerObjectInfoCache _cache = null!; // Initiated before use
- internal object?[]? _memberData = null;
- internal ISerializationSurrogate? _serializationSurrogate = null;
+ internal object?[]? _memberData;
+ internal ISerializationSurrogate? _serializationSurrogate;
internal StreamingContext _context;
- internal SerObjectInfoInit? _serObjectInfoInit = null;
+ internal SerObjectInfoInit? _serObjectInfoInit;
// Writing and Parsing information
internal long _objectId;
@@ -311,30 +311,30 @@ internal sealed class ReadObjectInfo
internal int _objectInfoId;
internal static int _readObjectInfoCounter;
- internal Type? _objectType = null;
+ internal Type? _objectType;
internal ObjectManager? _objectManager;
internal int _count;
- internal bool _isSi = false;
- internal bool _isTyped = false;
- internal bool _isSimpleAssembly = false;
+ internal bool _isSi;
+ internal bool _isTyped;
+ internal bool _isSimpleAssembly;
internal SerObjectInfoCache? _cache;
internal string[]? _wireMemberNames;
internal Type[]? _wireMemberTypes;
- private int _lastPosition = 0;
+ private int _lastPosition;
- internal ISerializationSurrogate? _serializationSurrogate = null;
+ internal ISerializationSurrogate? _serializationSurrogate;
internal StreamingContext _context;
// Si Read
internal List? _memberTypesList;
- internal SerObjectInfoInit? _serObjectInfoInit = null;
- internal IFormatterConverter? _formatterConverter = null;
+ internal SerObjectInfoInit? _serObjectInfoInit;
+ internal IFormatterConverter? _formatterConverter;
internal ReadObjectInfo() { }
diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectReader.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectReader.cs
index 93ae15e95de9a0..d37bba94c58625 100644
--- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectReader.cs
+++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectReader.cs
@@ -22,7 +22,7 @@ internal sealed class ObjectReader
// Top object and headers
internal long _topId;
- internal bool _isSimpleAssembly = false;
+ internal bool _isSimpleAssembly;
internal object? _topObject;
internal SerObjectInfoInit? _serObjectInfoInit;
internal IFormatterConverter? _formatterConverter;
@@ -44,7 +44,7 @@ internal sealed class ObjectReader
// Older formatters generate ids for valuetypes using a different counter than ref types. Newer ones use
// a single counter, only value types have a negative value. Need a way to handle older formats.
private const int ThresholdForValueTypeIds = int.MaxValue;
- private bool _oldFormatDetected = false;
+ private bool _oldFormatDetected;
private IntSizedArray? _valTypeObjectIdTable;
private readonly NameCache _typeCache = new NameCache();
diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs
index 5a99ef9660aadd..be64cb0f4ff4f7 100644
--- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs
+++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs
@@ -20,7 +20,6 @@ internal sealed class ObjectWriter
private readonly SerializationObjectManager _objectManager;
private long _topId;
- private readonly string? _topName = null;
private readonly InternalFE _formatterEnums;
private readonly SerializationBinder? _binder;
@@ -29,13 +28,14 @@ internal sealed class ObjectWriter
private IFormatterConverter? _formatterConverter;
- internal object[]? _crossAppDomainArray = null;
- internal List
internal readonly struct TransactionTraceIdentifier : IEquatable
{
- public static readonly TransactionTraceIdentifier Empty = default;
+ public static TransactionTraceIdentifier Empty => default;
public TransactionTraceIdentifier(string transactionIdentifier, int cloneIdentifier)
{
diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs
index 1fbd564bc24a13..e67f107826b685 100644
--- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs
+++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs
@@ -50,7 +50,7 @@ public sealed partial class PropertyBuilder : PropertyInfo
private object? def_value;
private MethodBuilder? set_method;
private MethodBuilder? get_method;
- private int table_idx = 0;
+ private int table_idx;
internal TypeBuilder typeb;
private Type[]? returnModReq;
private Type[]? returnModOpt;