Skip to content

Commit

Permalink
SerialPortStream: Reenable the readonly check.
Browse files Browse the repository at this point in the history
The keyword `readonly` is applied to objects that are classes, where it is safe to do so. Native methods do not have readonly flags set.
  • Loading branch information
jcurl committed Jan 5, 2023
1 parent 1c58634 commit 01ebfbe
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 38 deletions.
4 changes: 2 additions & 2 deletions code/Datastructures/CircularBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand Down Expand Up @@ -34,7 +34,7 @@ internal class CircularBuffer<T>
/// Circular buffer itself. Exposed by property "Array".
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private T[] m_Array;
private readonly T[] m_Array;

/// <summary>
/// Start index into the buffer. Exposed by property "Start".
Expand Down
8 changes: 4 additions & 4 deletions code/Datastructures/ReusableList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
internal class ReusableList<T> : IList<T> where T : class
{
private int m_Count;
private int m_MinCapacity;
private T[] m_ReusableList;
private T[][] m_ReusableListCache;
private readonly int m_MinCapacity;
private readonly T[] m_ReusableList;
private readonly T[][] m_ReusableListCache;

public ReusableList(int minCapacity, int maxCapacity)
{
Expand Down Expand Up @@ -87,7 +87,7 @@ public void CopyTo(T[] array, int arrayIndex)

private sealed class ArrayEnumerator : IEnumerator<T>
{
private ReusableList<T> m_Parent;
private readonly ReusableList<T> m_Parent;
private int m_Index;

public ArrayEnumerator(ReusableList<T> parent)
Expand Down
4 changes: 2 additions & 2 deletions code/Datastructures/TimerExpiry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand Down Expand Up @@ -49,7 +49,7 @@ namespace RJCP.Datastructures
/// </remarks>
internal sealed class TimerExpiry
{
private Stopwatch m_StopWatch = new Stopwatch();
private readonly Stopwatch m_StopWatch = new Stopwatch();
private int m_Milliseconds;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion code/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
[assembly: SuppressMessage("Style", "IDE0031:Use null propagation", Justification = ".NET Framework / Core compatibility")]
[assembly: SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "P/Invoke", Scope = "namespaceanddescendants", Target = "~N:RJCP.IO.Ports.Native")]
[assembly: SuppressMessage("Style", "IDE0056:Use index operator", Justification = ".NET Framework / Core compatibility")]
[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "P/Invoke", Scope = "namespaceanddescendants", Target = "~N:RJCP.IO.Ports.Native")]
[assembly: SuppressMessage("Major Code Smell", "S1066:Collapsible \"if\" statements should be merged", Justification = "No benefit")]
Expand Down
4 changes: 2 additions & 2 deletions code/Native/ReadToCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2021
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand Down Expand Up @@ -31,7 +31,7 @@ internal class ReadToCache

private Encoding m_Encoding = Encoding.GetEncoding("UTF-8");
private Decoder m_Decoder;
private LogSource m_Log;
private readonly LogSource m_Log;

public ReadToCache() : this(new LogSource()) { }

Expand Down
6 changes: 3 additions & 3 deletions code/Native/SerialBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand Down Expand Up @@ -288,7 +288,7 @@ void ISerialBufferStreamData.DiscardInBuffer()
}
}

private WaitHandle[] m_BufferStreamWaitForWriteCountHandles;
private readonly WaitHandle[] m_BufferStreamWaitForWriteCountHandles;

bool ISerialBufferStreamData.WaitForWrite(int count, int timeout)
{
Expand Down Expand Up @@ -352,7 +352,7 @@ int ISerialBufferStreamData.BytesToWrite
}
}

private WaitHandle[] m_BufferStreamFlushHandles;
private readonly WaitHandle[] m_BufferStreamFlushHandles;

bool ISerialBufferStreamData.Flush(int timeout)
{
Expand Down
4 changes: 2 additions & 2 deletions code/Native/WinNativeSerial.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand Down Expand Up @@ -32,7 +32,7 @@ internal class WinNativeSerial : INativeSerial
private CommOverlappedIo m_CommOverlappedIo;

private string m_Version;
private LogSource m_Log;
private readonly LogSource m_Log;

public WinNativeSerial() : this(new LogSource()) { }

Expand Down
4 changes: 2 additions & 2 deletions code/Native/Windows/CommErrorEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -8,7 +8,7 @@ namespace RJCP.IO.Ports.Native.Windows

internal class CommErrorEventArgs : EventArgs
{
private NativeMethods.ComStatErrors m_EventType;
private readonly NativeMethods.ComStatErrors m_EventType;

/// <summary>
/// Constructor.
Expand Down
4 changes: 2 additions & 2 deletions code/Native/Windows/CommEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -8,7 +8,7 @@ namespace RJCP.IO.Ports.Native.Windows

internal class CommEventArgs : EventArgs
{
private NativeMethods.SerialEventMask m_EventType;
private readonly NativeMethods.SerialEventMask m_EventType;

/// <summary>
/// Constructor.
Expand Down
4 changes: 2 additions & 2 deletions code/Native/Windows/CommOverlappedIo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2021
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand Down Expand Up @@ -94,7 +94,7 @@ internal class CommOverlappedIo : IDisposable
private bool m_ReadByteEof;

private string m_Name;
private LogSource m_Log;
private readonly LogSource m_Log;
#endregion

#region Constructors
Expand Down
4 changes: 2 additions & 2 deletions code/Native/Windows/CommProperties.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -13,7 +13,7 @@ namespace RJCP.IO.Ports.Native.Windows
/// </summary>
internal sealed class CommProperties
{
private SafeFileHandle m_ComPortHandle;
private readonly SafeFileHandle m_ComPortHandle;
private NativeMethods.CommProp m_CommProp = new NativeMethods.CommProp();

internal CommProperties(SafeFileHandle handle)
Expand Down
4 changes: 2 additions & 2 deletions code/Native/Windows/CommState.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -13,7 +13,7 @@ namespace RJCP.IO.Ports.Native.Windows
/// </summary>
internal sealed class CommState
{
private SafeFileHandle m_ComPortHandle;
private readonly SafeFileHandle m_ComPortHandle;
private NativeMethods.DCB m_Dcb = new NativeMethods.DCB();

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions code/SerialErrorReceivedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -11,7 +11,7 @@ namespace RJCP.IO.Ports
/// </summary>
public class SerialErrorReceivedEventArgs : EventArgs
{
private SerialError m_EventType;
private readonly SerialError m_EventType;

/// <summary>
/// Constructor
Expand Down
4 changes: 2 additions & 2 deletions code/SerialPinChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2016
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -11,7 +11,7 @@ namespace RJCP.IO.Ports
/// </summary>
public class SerialPinChangedEventArgs : EventArgs
{
private SerialPinChange m_EventType;
private readonly SerialPinChange m_EventType;

/// <summary>
/// Constructor.
Expand Down
6 changes: 3 additions & 3 deletions code/SerialPortStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2021
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand Down Expand Up @@ -45,7 +45,7 @@ public partial class SerialPortStream : Stream, ISerialPortStream
private INativeSerial m_NativeSerial;
private SerialBuffer m_Buffer;
private ReadToCache m_ReadTo;
private LogSource m_Log;
private readonly LogSource m_Log;

#region Public constants
/// <summary>
Expand Down Expand Up @@ -2012,7 +2012,7 @@ public override void SetLength(long value)

#region Event Handling and Abstraction
private readonly object m_EventLock = new object();
private ManualResetEvent m_EventProcessing = new ManualResetEvent(false);
private readonly ManualResetEvent m_EventProcessing = new ManualResetEvent(false);
private SerialData m_SerialDataFlags = SerialData.NoData;
private SerialError m_SerialErrorFlags = SerialError.NoError;
private SerialPinChange m_SerialPinChange = SerialPinChange.NoChange;
Expand Down
2 changes: 1 addition & 1 deletion code/System/IO/Ports/SerialPort.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace System.IO.Ports
{
/// <summary>
/// Class SerialPort compatibility layer for .NET Stanard 1.5
/// Class SerialPort compatibility layer for .NET Standard 1.5
/// </summary>
internal class SerialPort
{
Expand Down
4 changes: 2 additions & 2 deletions code/Trace/LineSplitter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2019-2021
// Copyright © Jason Curl 2019-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -12,7 +12,7 @@ namespace RJCP.IO.Ports.Trace

internal sealed class LineSplitter : IEnumerable<string>
{
private StringBuilder m_Line = new StringBuilder();
private readonly StringBuilder m_Line = new StringBuilder();
private List<string> m_Lines = new List<string>();

public bool IsCached { get { return m_Line.Length > 0; } }
Expand Down
8 changes: 6 additions & 2 deletions code/Trace/LogSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © Jason Curl 2012-2021
// Copyright © Jason Curl 2012-2023
// Sources at https://github.com/jcurl/SerialPortStream
// Licensed under the Microsoft Public License (Ms-PL)

Expand All @@ -25,9 +25,13 @@ namespace RJCP.IO.Ports.Trace
/// </remarks>
internal sealed class LogSource : IDisposable
{
private string m_Name;
private readonly string m_Name;
private TraceSource m_TraceSource;
#if NETSTANDARD1_5
private long m_TraceLevels;
#else
private readonly long m_TraceLevels;
#endif

public LogSource()
{
Expand Down

0 comments on commit 01ebfbe

Please sign in to comment.