From 57472d3bfff954428989f5828de7cf6ce964efe9 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 26 Jun 2020 17:13:57 -0400 Subject: [PATCH] Enable CA1805 --- eng/CodeAnalysis.ruleset | 2 +- .../Common/src/System/Net/LazyAsyncResult.cs | 1 - .../src/ConsoleLogger.cs | 45 +++++++++---------- .../src/System/Linq/Expressions/Utils.cs | 2 + .../src/System/Net/Http/HttpClientHandler.cs | 2 +- .../src/System/Net/Cookie.cs | 7 +-- .../Tracing/TraceLogging/XplatEventLogger.cs | 6 +-- .../PortableThreadPool.HillClimbing.cs | 4 +- .../PortableThreadPool.WaitThread.cs | 4 +- .../System/Threading/PortableThreadPool.cs | 4 +- .../Formatters/Binary/BinaryArray.cs | 2 +- .../Formatters/Binary/BinaryFormatter.cs | 2 +- .../Binary/BinaryFormatterWriter.cs | 4 +- .../Formatters/Binary/BinaryObjectInfo.cs | 30 ++++++------- .../Formatters/Binary/BinaryObjectReader.cs | 4 +- .../Formatters/Binary/BinaryObjectWriter.cs | 35 +++++---------- .../Formatters/Binary/BinaryUtilClasses.cs | 9 ++-- .../Formatters/Binary/ObjectMap.cs | 2 +- .../Formatters/Binary/ObjectProgress.cs | 2 +- .../Runtime/Serialization/MemberHolder.cs | 1 - .../Runtime/Serialization/ObjectManager.cs | 6 +-- .../src/Internal/ConcurrentQueue.cs | 2 +- .../Transactions/EnlistmentTraceIdentifier.cs | 2 +- .../TransactionTraceIdentifier.cs | 2 +- .../Reflection/Emit/PropertyBuilder.Mono.cs | 2 +- 25 files changed, 81 insertions(+), 101 deletions(-) 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? _internalCrossAppDomainArray = null; +#pragma warning disable 0649 // Field is never assigned to, and will always have its default value null + internal object[]? _crossAppDomainArray; +#pragma warning restore 0649 - private object? _previousObj = null; - private long _previousId = 0; + private object? _previousObj; + private long _previousId; - private Type? _previousType = null; + private Type? _previousType; private InternalPrimitiveTypeE _previousCode = InternalPrimitiveTypeE.Invalid; internal ObjectWriter(ISurrogateSelector? selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder? binder) @@ -208,7 +208,6 @@ private void Write(WriteObjectInfo objectInfo, WriteObjectInfo[] memberObjectInfos) { int numItems = memberNames.Length; - NameInfo? topNameInfo = null; Debug.Assert(_serWriter != null); if (memberNameInfo != null) @@ -216,19 +215,10 @@ private void Write(WriteObjectInfo objectInfo, memberNameInfo._objectId = objectInfo._objectId; _serWriter.WriteObject(memberNameInfo, typeNameInfo, numItems, memberNames, memberTypes, memberObjectInfos); } - else if ((objectInfo._objectId == _topId) && (_topName != null)) - { - topNameInfo = MemberToNameInfo(_topName); - topNameInfo._objectId = objectInfo._objectId; - _serWriter.WriteObject(topNameInfo, typeNameInfo, numItems, memberNames, memberTypes, memberObjectInfos); - } - else + else if (!ReferenceEquals(objectInfo._objectType, Converter.s_typeofString)) { - if (!ReferenceEquals(objectInfo._objectType, Converter.s_typeofString)) - { - typeNameInfo._objectId = objectInfo._objectId; - _serWriter.WriteObject(typeNameInfo, null, numItems, memberNames, memberTypes, memberObjectInfos); - } + typeNameInfo._objectId = objectInfo._objectId; + _serWriter.WriteObject(typeNameInfo, null, numItems, memberNames, memberTypes, memberObjectInfos); } Debug.Assert(memberNameInfo != null); @@ -253,11 +243,6 @@ private void Write(WriteObjectInfo objectInfo, memberNameInfo._objectId = objectInfo._objectId; _serWriter.WriteObjectEnd(memberNameInfo, typeNameInfo); } - else if ((objectInfo._objectId == _topId) && (_topName != null)) - { - _serWriter.WriteObjectEnd(topNameInfo!, typeNameInfo); - PutNameInfo(topNameInfo!); - } else if (!ReferenceEquals(objectInfo._objectType, Converter.s_typeofString)) { _serWriter.WriteObjectEnd(typeNameInfo, typeNameInfo); @@ -973,7 +958,7 @@ internal InternalPrimitiveTypeE ToCode(Type? type) } } - private Dictionary? _assemblyToIdTable = null; + private Dictionary? _assemblyToIdTable; private long GetAssemblyId(WriteObjectInfo objectInfo) { //use objectInfo to get assembly string with new criteria diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryUtilClasses.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryUtilClasses.cs index a00c57bdf82e4c..758ad794b5bf71 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryUtilClasses.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryUtilClasses.cs @@ -42,7 +42,7 @@ internal sealed class ParseRecord // Array Element Type internal string? _arrayElementTypeString; internal Type? _arrayElementType; - internal bool _isArrayVariant = false; + internal bool _isArrayVariant; internal InternalPrimitiveTypeE _arrayElementTypeCode; // Parsed array information @@ -62,7 +62,7 @@ internal sealed class ParseRecord internal ReadObjectInfo? _objectInfo; // ValueType Fixup needed - internal bool _isValueTypeFixup = false; + internal bool _isValueTypeFixup; // Created object internal object? _newObj; @@ -360,7 +360,7 @@ internal void IncreaseCapacity(int index) internal sealed class NameCache { private static readonly ConcurrentDictionary s_ht = new ConcurrentDictionary(); - private string? _name = null; + private string? _name; internal object? GetCachedValue(string name) { @@ -378,7 +378,6 @@ internal sealed class ValueFixup internal ValueFixupEnum _valueFixupEnum = ValueFixupEnum.Empty; internal Array? _arrayObj; internal int[]? _indexMap; - internal object? _header = null; internal object? _memberObject; internal ReadObjectInfo? _objectInfo; internal string? _memberName; @@ -450,7 +449,7 @@ internal sealed class NameInfo internal bool _transmitTypeOnMember; internal bool _isParentTypeOnObject; internal InternalArrayTypeE _arrayEnum; - private bool _sealedStatusChecked = false; + private bool _sealedStatusChecked; internal NameInfo() { } diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectMap.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectMap.cs index b7620a23f37e5f..3712a7aab0d4a7 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectMap.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectMap.cs @@ -19,7 +19,7 @@ internal sealed class ObjectMap internal string[] _memberNames; internal ReadObjectInfo _objectInfo; internal bool _isInitObjectInfo = true; - internal ObjectReader? _objectReader = null; + internal ObjectReader? _objectReader; internal int _objectId; internal BinaryAssemblyInfo _assemblyInfo; diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectProgress.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectProgress.cs index 94febe485f0733..495329702f8c9e 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectProgress.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/ObjectProgress.cs @@ -17,7 +17,7 @@ internal sealed class ObjectProgress internal bool _isInitial; internal int _count; //Progress count internal BinaryTypeEnum _expectedType = BinaryTypeEnum.ObjectUrt; - internal object? _expectedTypeInformation = null; + internal object? _expectedTypeInformation; internal string? _name; internal InternalObjectTypeE _objectTypeEnum = InternalObjectTypeE.Empty; diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs index 42991a4193cd32..6349de93629e28 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs @@ -8,7 +8,6 @@ namespace System.Runtime.Serialization { internal sealed class MemberHolder { - internal readonly MemberInfo[]? _members = null; internal readonly Type _memberType; internal readonly StreamingContext _context; diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs index 016dea5c266d37..ee9867c447da4a 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs @@ -20,7 +20,7 @@ public class ObjectManager private SerializationEventHandler? _onDeserializedHandler; internal ObjectHolder[] _objects; - internal object? _topObject = null; + internal object? _topObject; internal ObjectHolderList? _specialFixupObjects; //This is IObjectReference, ISerializable, or has a Surrogate. internal long _fixupCount; internal readonly ISurrogateSelector? _selector; @@ -1017,8 +1017,8 @@ internal sealed class ObjectHolder internal int _flags; private bool _markForFixupWhenAvailable; private ValueTypeFixupInfo? _valueFixup; - private TypeLoadExceptionHolder? _typeLoad = null; - private bool _reachable = false; + private TypeLoadExceptionHolder? _typeLoad; + private bool _reachable; internal ObjectHolder(long objID) : this(null, objID, null, null, 0, null, null) { diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs index db5af01adc1c1f..6af18b70a80a03 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs @@ -38,7 +38,7 @@ internal class ConcurrentQueue : IProducerConsumerCollection private volatile Segment _tail; private const int SEGMENT_SIZE = 32; //number of snapshot takers, GetEnumerator(), ToList() and ToArray() operations take snapshot. - internal volatile int _numSnapshotTakers = 0; + internal volatile int _numSnapshotTakers; /// /// Initializes a new instance of the class. diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs index 057004030f1056..466b0febc5314c 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs @@ -11,7 +11,7 @@ namespace System.Transactions /// internal readonly struct EnlistmentTraceIdentifier : IEquatable { - public static readonly EnlistmentTraceIdentifier Empty = default; + public static EnlistmentTraceIdentifier Empty => default; public EnlistmentTraceIdentifier( Guid resourceManagerIdentifier, diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs index 164f2b1f38226e..1962643ffbe171 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs @@ -11,7 +11,7 @@ namespace System.Transactions /// 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;