Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<Rule Id="CA1725" Action="Info" /> <!-- Parameter names should match base declaration -->
<Rule Id="CA1801" Action="None" /> <!-- Review unused parameters -->
<Rule Id="CA1802" Action="Warning" /> <!-- Use literals where appropriate -->
<Rule Id="CA1805" Action="Info" /> <!-- Do not initialize unnecessarily -->
<Rule Id="CA1805" Action="Warning" /> <!-- Do not initialize unnecessarily -->
<Rule Id="CA1806" Action="None" /> <!-- Do not ignore method results -->
<Rule Id="CA1810" Action="Warning" /> <!-- Initialize reference type static fields inline -->
<Rule Id="CA1812" Action="None" /> <!-- Avoid uninstantiated internal classes -->
Expand Down
1 change: 0 additions & 1 deletion src/libraries/Common/src/System/Net/LazyAsyncResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
7 changes: 4 additions & 3 deletions src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ namespace System.Diagnostics.Tracing
{
internal class XplatEventLogger : EventListener
{
private static Lazy<string?> eventSourceNameFilter = new Lazy<string?>(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter"));
private static Lazy<string?> eventSourceEventFilter = new Lazy<string?>(() => CompatibilitySwitch.GetValueInternal("EventNameFilter"));
private static readonly Lazy<string?> eventSourceNameFilter = new Lazy<string?>(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter"));
private static readonly Lazy<string?> eventSourceEventFilter = new Lazy<string?>(() => CompatibilitySwitch.GetValueInternal("EventNameFilter"));

public XplatEventLogger() {}

private static bool initializedPersistentListener = false;
private static bool initializedPersistentListener;

public static EventListener? InitializePersistentListener()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public CompletedWaitHandle(RegisteredWaitHandle completedHandle, bool timedOut)
/// <summary>
/// The number of user-registered waits on this wait thread.
/// </summary>
private int _numUserWaits = 0;
private int _numUserWaits;

/// <summary>
/// A list of removals of wait handles that are waiting for the wait thread to process.
Expand All @@ -160,7 +160,7 @@ public CompletedWaitHandle(RegisteredWaitHandle completedHandle, bool timedOut)
/// <summary>
/// The number of pending removals.
/// </summary>
private int _numPendingRemoves = 0;
private int _numPendingRemoves;

/// <summary>
/// An event to notify the wait thread that there are pending adds or removals of wait handles so it needs to wake up.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -64,7 +64,7 @@ private struct CacheLineSeparated

private readonly LowLevelLock _hillClimbingThreadAdjustmentLock = new LowLevelLock();

private volatile int _numRequestedWorkers = 0;
private volatile int _numRequestedWorkers;

private PortableThreadPool()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ internal sealed class BinaryFormatterWriter
private readonly ObjectWriter _objectWriter;
private readonly BinaryWriter _dataWriter;

private int _consecutiveNullArrayEntryCount = 0;
private int _consecutiveNullArrayEntryCount;
private Dictionary<string, ObjectMapInfo>? _objectMapTable;

private BinaryObject? _binaryObject;
private BinaryObjectWithMap? _binaryObjectWithMap;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Type>? _memberTypesList;
internal SerObjectInfoInit? _serObjectInfoInit = null;
internal IFormatterConverter? _formatterConverter = null;
internal SerObjectInfoInit? _serObjectInfoInit;
internal IFormatterConverter? _formatterConverter;

internal ReadObjectInfo() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,13 +28,14 @@ internal sealed class ObjectWriter

private IFormatterConverter? _formatterConverter;

internal object[]? _crossAppDomainArray = null;
internal List<object>? _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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field can be removed, but pulling on that thread leads to a whole bunch of stuff that can be deleted around old AppDomain logic, and given our stance on this assembly, I decided to just leave things as they are.


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)
Expand Down Expand Up @@ -208,27 +208,17 @@ private void Write(WriteObjectInfo objectInfo,
WriteObjectInfo[] memberObjectInfos)
{
int numItems = memberNames.Length;
NameInfo? topNameInfo = null;

Debug.Assert(_serWriter != null);
if (memberNameInfo != null)
{
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);
Expand All @@ -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);
Expand Down Expand Up @@ -973,7 +958,7 @@ internal InternalPrimitiveTypeE ToCode(Type? type)
}
}

private Dictionary<string, long>? _assemblyToIdTable = null;
private Dictionary<string, long>? _assemblyToIdTable;
private long GetAssemblyId(WriteObjectInfo objectInfo)
{
//use objectInfo to get assembly string with new criteria
Expand Down
Loading