Skip to content

Commit f40a002

Browse files
authored
1 parent 7e145ef commit f40a002

12 files changed

Lines changed: 46 additions & 49 deletions

src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ internal sealed class PropVariant : IDisposable
1919
{
2020
// This is actually a VarEnum value, but the VarEnum type requires 4 bytes instead of the expected 2.
2121
[FieldOffset(0)]
22-
private ushort _valueType;
22+
private readonly ushort _valueType;
2323

2424
[FieldOffset(8)]
25-
private IntPtr _ptr;
25+
private readonly IntPtr _ptr;
2626

2727
/// <summary>
2828
/// Set a string value.

src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ private bool CollectArgs(string[] args, ref int i)
13511351
private Serialization.DataFormat _outFormat = Serialization.DataFormat.Text;
13521352
private bool _outputFormatSpecified = false;
13531353
private Serialization.DataFormat _inFormat = Serialization.DataFormat.Text;
1354-
private Collection<CommandParameter> _collectedArgs = new Collection<CommandParameter>();
1354+
private readonly Collection<CommandParameter> _collectedArgs = new Collection<CommandParameter>();
13551355
private string? _file;
13561356
private string? _executionPolicy;
13571357
private string? _settingsFile;

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3248,7 +3248,7 @@ internal enum CHAR_INFO_Attributes : uint
32483248
}
32493249

32503250
[TraceSourceAttribute("ConsoleControl", "Console control methods")]
3251-
private static PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleControl", "Console control methods");
3251+
private static readonly PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleControl", "Console control methods");
32523252
#endif
32533253
}
32543254
}

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ internal LocalRunspace LocalRunspace
739739

740740
public class ConsoleColorProxy
741741
{
742-
private ConsoleHostUserInterface _ui;
742+
private readonly ConsoleHostUserInterface _ui;
743743

744744
public ConsoleColorProxy(ConsoleHostUserInterface ui)
745745
{
@@ -2844,12 +2844,12 @@ private string EvaluateDebugPrompt()
28442844
return promptString;
28452845
}
28462846

2847-
private ConsoleHost _parent;
2848-
private bool _isNested;
2847+
private readonly ConsoleHost _parent;
2848+
private readonly bool _isNested;
28492849
private bool _shouldExit;
2850-
private Executor _exec;
2851-
private Executor _promptExec;
2852-
private object _syncObject = new object();
2850+
private readonly Executor _exec;
2851+
private readonly Executor _promptExec;
2852+
private readonly object _syncObject = new object();
28532853
private bool _isRunspacePushed = false;
28542854
private bool _runspacePopped = false;
28552855

@@ -2858,7 +2858,7 @@ private string EvaluateDebugPrompt()
28582858

28592859
// threadsafety guaranteed by enclosing class
28602860

2861-
private static Stack<InputLoop> s_instanceStack = new Stack<InputLoop>();
2861+
private static readonly Stack<InputLoop> s_instanceStack = new Stack<InputLoop>();
28622862
}
28632863

28642864
[Serializable]
@@ -2913,7 +2913,7 @@ private class ConsoleHostStartupException : Exception
29132913

29142914
// Set to Unknown so that we avoid saving/restoring the console mode if we don't have a console.
29152915
private ConsoleControl.ConsoleModes _savedConsoleMode = ConsoleControl.ConsoleModes.Unknown;
2916-
private ConsoleControl.ConsoleModes _initialConsoleMode = ConsoleControl.ConsoleModes.Unknown;
2916+
private readonly ConsoleControl.ConsoleModes _initialConsoleMode = ConsoleControl.ConsoleModes.Unknown;
29172917
#endif
29182918
private Thread _breakHandlerThread;
29192919
private bool _isDisposed;
@@ -2922,7 +2922,7 @@ private class ConsoleHostStartupException : Exception
29222922
internal Lazy<TextReader> ConsoleIn { get; } = new Lazy<TextReader>(() => Console.In);
29232923

29242924
private string _savedWindowTitle = string.Empty;
2925-
private Version _ver = PSVersionInfo.PSVersion;
2925+
private readonly Version _ver = PSVersionInfo.PSVersion;
29262926
private int _exitCodeFromRunspace;
29272927
private bool _noExit = true;
29282928
private bool _setShouldExitCalled;
@@ -2942,7 +2942,7 @@ private class ConsoleHostStartupException : Exception
29422942
private bool _shouldEndSession;
29432943
private int _beginApplicationNotifyCount;
29442944

2945-
private ConsoleTextWriter _consoleWriter;
2945+
private readonly ConsoleTextWriter _consoleWriter;
29462946
private WrappedSerializer _outputSerializer;
29472947
private WrappedSerializer _errorSerializer;
29482948
private bool _displayDebuggerBanner;
@@ -2958,11 +2958,10 @@ private class ConsoleHostStartupException : Exception
29582958
internal static InitialSessionState DefaultInitialSessionState;
29592959

29602960
[TraceSource("ConsoleHost", "ConsoleHost subclass of S.M.A.PSHost")]
2961-
private static
2962-
PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHost", "ConsoleHost subclass of S.M.A.PSHost");
2961+
private static readonly PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHost", "ConsoleHost subclass of S.M.A.PSHost");
29632962

29642963
[TraceSource("ConsoleHostRunspaceInit", "Initialization code for ConsoleHost's Runspace")]
2965-
private static PSTraceSource s_runspaceInitTracer =
2964+
private static readonly PSTraceSource s_runspaceInitTracer =
29662965
PSTraceSource.GetTracer("ConsoleHostRunspaceInit", "Initialization code for ConsoleHost's Runspace", false);
29672966
}
29682967

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,17 +1299,16 @@ private static
12991299

13001300
#endregion helpers
13011301

1302-
private ConsoleColor defaultForeground = ConsoleColor.Gray;
1302+
private readonly ConsoleColor defaultForeground = ConsoleColor.Gray;
13031303

1304-
private ConsoleColor defaultBackground = ConsoleColor.Black;
1304+
private readonly ConsoleColor defaultBackground = ConsoleColor.Black;
13051305

1306-
private ConsoleHostUserInterface parent = null;
1306+
private readonly ConsoleHostUserInterface parent = null;
13071307

13081308
private ConsoleControl.KEY_EVENT_RECORD cachedKeyEvent;
13091309

13101310
[TraceSourceAttribute("ConsoleHostRawUserInterface", "Console host's subclass of S.M.A.Host.RawConsole")]
1311-
private static
1312-
PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleHostRawUserInterface", "Console host's subclass of S.M.A.Host.RawConsole");
1311+
private static readonly PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleHostRawUserInterface", "Console host's subclass of S.M.A.Host.RawConsole");
13131312
}
13141313
} // namespace
13151314

@@ -1336,7 +1335,7 @@ namespace Microsoft.PowerShell
13361335
internal sealed class ConsoleHostRawUserInterface : PSHostRawUserInterface
13371336
{
13381337

1339-
private ConsoleHostUserInterface _parent = null;
1338+
private readonly ConsoleHostUserInterface _parent = null;
13401339

13411340
internal ConsoleHostRawUserInterface(ConsoleHostUserInterface mshConsole) : base()
13421341
{

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostTranscript.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal void StartTranscribing(string transcriptFilename, bool shouldAppend)
6161
}
6262
}
6363
*/
64-
private string _transcriptFileName = string.Empty;
64+
private readonly string _transcriptFileName = string.Empty;
6565

6666
internal string StopTranscribing()
6767
{
@@ -127,7 +127,7 @@ internal void WriteToTranscript(ReadOnlySpan<char> text, bool newLine)
127127
}
128128

129129
private StreamWriter _transcriptionWriter;
130-
private object _transcriptionStateLock = new object();
130+
private readonly object _transcriptionStateLock = new object();
131131
}
132132
} // namespace
133133

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal partial class ConsoleHostUserInterface : System.Management.Automation.H
4242
/// <summary>
4343
/// This is a test hook for programmatically reading and writing ConsoleHost I/O.
4444
/// </summary>
45-
private static PSHostUserInterface s_h = null;
45+
private static readonly PSHostUserInterface s_h = null;
4646

4747
/// <summary>
4848
/// Return true if the console supports a VT100 like virtual terminal.
@@ -2158,7 +2158,7 @@ private bool TryInvokeUserDefinedReadLine(out string input)
21582158

21592159
// used to serialize access to instance data
21602160

2161-
private object _instanceLock = new object();
2161+
private readonly object _instanceLock = new object();
21622162

21632163
// If this is true, class throws on read or prompt method which require
21642164
// access to console.
@@ -2182,16 +2182,15 @@ internal void HandleThrowOnReadAndPrompt()
21822182

21832183
// this is a test hook for the ConsoleInteractiveTestTool, which sets this field to true.
21842184

2185-
private bool _isInteractiveTestToolListening;
2185+
private readonly bool _isInteractiveTestToolListening;
21862186

21872187
// This instance data is "read-only" and need not have access serialized.
21882188

2189-
private ConsoleHostRawUserInterface _rawui;
2190-
private ConsoleHost _parent;
2189+
private readonly ConsoleHostRawUserInterface _rawui;
2190+
private readonly ConsoleHost _parent;
21912191

21922192
[TraceSourceAttribute("ConsoleHostUserInterface", "Console host's subclass of S.M.A.Host.Console")]
2193-
private static
2194-
PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHostUserInterface", "Console host's subclass of S.M.A.Host.Console");
2193+
private static readonly PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHostUserInterface", "Console host's subclass of S.M.A.Host.Console");
21952194
}
21962195
} // namespace
21972196

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleTextWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ public override
9393
_ui.WriteToConsole(a, transcribeResult: true);
9494
}
9595

96-
private ConsoleHostUserInterface _ui;
96+
private readonly ConsoleHostUserInterface _ui;
9797
}
9898
}

src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private void PipelineStateChangedHandler(object sender, PipelineStateEventArgs e
149149
}
150150
}
151151

152-
private System.Threading.ManualResetEvent _eventHandle = new System.Threading.ManualResetEvent(false);
152+
private readonly System.Threading.ManualResetEvent _eventHandle = new System.Threading.ManualResetEvent(false);
153153
}
154154

155155
internal void ExecuteCommandAsync(string command, out Exception exceptionThrown, ExecutionOptions options)
@@ -729,14 +729,14 @@ internal static void CancelCurrentExecutor()
729729
// to currentExecutor is guarded by staticStateLock, and static initializers are run by the CLR at program init time.
730730

731731
private static Executor s_currentExecutor;
732-
private static object s_staticStateLock = new object();
732+
private static readonly object s_staticStateLock = new object();
733733

734-
private ConsoleHost _parent;
734+
private readonly ConsoleHost _parent;
735735
private Pipeline _pipeline;
736736
private bool _cancelled;
737737
internal bool useNestedPipelines;
738-
private object _instanceStateLock = new object();
739-
private bool _isPromptFunctionExecutor;
738+
private readonly object _instanceStateLock = new object();
739+
private readonly bool _isPromptFunctionExecutor;
740740
}
741741
} // namespace
742742

src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ internal override
399399
int
400400
IndexWhereFound = -1;
401401

402-
private int _idToFind = -1;
403-
private Int64 _sourceIdToFind;
402+
private readonly int _idToFind = -1;
403+
private readonly Int64 _sourceIdToFind;
404404
}
405405

406406
/// <summary>
@@ -676,9 +676,9 @@ internal override
676676
return true;
677677
}
678678

679-
private PSHostRawUserInterface _rawUi;
680-
private int _maxHeight;
681-
private int _maxWidth;
679+
private readonly PSHostRawUserInterface _rawUi;
680+
private readonly int _maxHeight;
681+
private readonly int _maxWidth;
682682

683683
internal int Tally;
684684
}
@@ -1000,7 +1000,7 @@ internal static
10001000

10011001
#endregion
10021002

1003-
private ArrayList _topLevelNodes = new ArrayList();
1003+
private readonly ArrayList _topLevelNodes = new ArrayList();
10041004
private int _nodeCount;
10051005

10061006
private const int maxNodeCount = 128;

0 commit comments

Comments
 (0)