From 6e91096027973827be90601ab649d877494b79fd Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 26 Oct 2020 17:12:35 +0000 Subject: [PATCH] Fix IDE0044: MakeFieldReadonly part 4 src\Microsoft.PowerShell.Commands.Utility\ --- .../commands/utility/CsvCommands.cs | 2 +- .../commands/utility/CustomSerialization.cs | 10 +++++----- .../commands/utility/DebugRunspaceCommand.cs | 2 +- .../commands/utility/ExportAliasCommand.cs | 2 +- .../OutGridView/ExpressionColumnInfo.cs | 2 +- .../utility/FormatAndOutput/OutGridView/HeaderInfo.cs | 2 +- .../FormatAndOutput/OutGridView/OriginalColumnInfo.cs | 4 ++-- .../FormatAndOutput/OutGridView/OutGridViewCommand.cs | 4 ++-- .../FormatAndOutput/OutGridView/OutWindowProxy.cs | 8 ++++---- .../OutGridView/ScalarTypeColumnInfo.cs | 4 ++-- .../FormatAndOutput/common/WriteFormatDataCommand.cs | 2 +- .../FormatAndOutput/out-printer/PrinterLineOutput.cs | 6 +++--- .../utility/FormatAndOutput/out-string/Out-String.cs | 2 +- .../commands/utility/GetMember.cs | 2 +- .../commands/utility/GetRandomCommand.cs | 8 ++++---- .../commands/utility/ImplicitRemotingCommands.cs | 6 +++--- .../commands/utility/MarkdownOptionCommands.cs | 2 +- .../commands/utility/Measure-Object.cs | 2 +- .../commands/utility/ObjectCommandComparer.cs | 8 ++++---- .../commands/utility/OrderObjectBase.cs | 6 +++--- .../commands/utility/Select-Object.cs | 9 ++++++--- .../commands/utility/Send-MailMessage.cs | 2 +- .../commands/utility/ShowCommand/ShowCommandProxy.cs | 4 ++-- .../commands/utility/StartSleepCommand.cs | 2 +- .../commands/utility/TimeExpressionCommand.cs | 2 +- .../commands/utility/Update-TypeData.cs | 2 +- .../commands/utility/WaitEventCommand.cs | 4 ++-- .../WebCmdlet/Common/InvokeRestMethodCommand.Common.cs | 6 +++--- .../utility/WebCmdlet/ConvertFromJsonCommand.cs | 2 +- .../commands/utility/WebCmdlet/ConvertToJsonCommand.cs | 2 +- .../commands/utility/WebCmdlet/CoreCLR/WebProxy.cs | 2 +- .../commands/utility/WebCmdlet/StreamHelper.cs | 4 ++-- .../commands/utility/XmlCommands.cs | 2 +- .../commands/utility/trace/MshHostTraceListener.cs | 4 ++-- .../commands/utility/trace/TraceExpressionCommand.cs | 6 +++--- .../commands/utility/trace/TraceListenerCommandBase.cs | 2 +- 36 files changed, 71 insertions(+), 68 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs index bea8b55d7c1..b4b43ab83ea 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs @@ -879,7 +879,7 @@ protected override void ProcessRecord() /// internal class ExportCsvHelper : IDisposable { - private char _delimiter; + private readonly char _delimiter; private readonly BaseCsvWritingCommand.QuoteKind _quoteKind; private readonly HashSet _quoteFields; private readonly StringBuilder _outputString; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs index 2c85a64cf18..22c224820c5 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs @@ -21,17 +21,17 @@ internal class CustomSerialization /// /// Depth of serialization. /// - private int _depth; + private readonly int _depth; /// /// XmlWriter to be used for writing. /// - private XmlWriter _writer; + private readonly XmlWriter _writer; /// /// Whether type information should be included in the xml. /// - private bool _notypeinformation; + private readonly bool _notypeinformation; /// /// CustomerSerializer used for formatting the output for _writer. @@ -191,7 +191,7 @@ internal class /// /// Xml writer to be used. /// - private XmlWriter _writer; + private readonly XmlWriter _writer; /// /// Check first call for every pipeline object to write Object tag else property tag. @@ -201,7 +201,7 @@ internal class /// /// Should the type information to be shown. /// - private bool _notypeinformation; + private readonly bool _notypeinformation; /// /// Check object call. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/DebugRunspaceCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/DebugRunspaceCommand.cs index 355d94912af..1a560a0010d 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/DebugRunspaceCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/DebugRunspaceCommand.cs @@ -43,7 +43,7 @@ public sealed class DebugRunspaceCommand : PSCmdlet // Debugging to persist until Ctrl+C or Debugger 'Exit' stops cmdlet. private bool _debugging; - private ManualResetEventSlim _newRunningScriptEvent = new ManualResetEventSlim(true); + private readonly ManualResetEventSlim _newRunningScriptEvent = new ManualResetEventSlim(true); private RunspaceAvailability _previousRunspaceAvailability = RunspaceAvailability.None; #endregion diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs index 1ac3e781ab7..431f30a3dcc 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ExportAliasCommand.cs @@ -310,7 +310,7 @@ protected override void EndProcessing() /// /// Holds all the matching aliases for writing to the file. /// - private Collection _matchingAliases = new Collection(); + private readonly Collection _matchingAliases = new Collection(); private static string GetAliasLine(AliasInfo alias, string formatString) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ExpressionColumnInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ExpressionColumnInfo.cs index a9d60def958..0e529004aec 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ExpressionColumnInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ExpressionColumnInfo.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.Commands { internal class ExpressionColumnInfo : ColumnInfo { - private PSPropertyExpression _expression; + private readonly PSPropertyExpression _expression; internal ExpressionColumnInfo(string staleObjectPropertyName, string displayName, PSPropertyExpression expression) : base(staleObjectPropertyName, displayName) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/HeaderInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/HeaderInfo.cs index d7d863e29b8..c88cdd0bcb0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/HeaderInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/HeaderInfo.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.Commands { internal class HeaderInfo { - private List _columns = new List(); + private readonly List _columns = new List(); internal void AddColumn(ColumnInfo col) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OriginalColumnInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OriginalColumnInfo.cs index 48a9004e604..3db37f3528e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OriginalColumnInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OriginalColumnInfo.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.Commands { internal class OriginalColumnInfo : ColumnInfo { - private string _liveObjectPropertyName; - private OutGridViewCommand _parentCmdlet; + private readonly string _liveObjectPropertyName; + private readonly OutGridViewCommand _parentCmdlet; internal OriginalColumnInfo(string staleObjectPropertyName, string displayName, string liveObjectPropertyName, OutGridViewCommand parentCmdlet) : base(staleObjectPropertyName, displayName) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs index b95e9968c5c..a587a88b3a0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs @@ -326,7 +326,7 @@ internal static GridHeader ConstructGridHeader(PSObject input, OutGridViewComman internal class ScalarTypeHeader : GridHeader { - private Type _originalScalarType; + private readonly Type _originalScalarType; internal ScalarTypeHeader(OutGridViewCommand parentCmd, PSObject input) : base(parentCmd) { @@ -352,7 +352,7 @@ internal override void ProcessInputObject(PSObject input) internal class NonscalarTypeHeader : GridHeader { - private AppliesTo _appliesTo = null; + private readonly AppliesTo _appliesTo = null; internal NonscalarTypeHeader(OutGridViewCommand parentCmd, PSObject input) : base(parentCmd) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs index 55158034368..446b2f2568f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs @@ -28,15 +28,15 @@ internal class OutWindowProxy : IDisposable private bool _isWindowStarted; - private string _title; + private readonly string _title; - private OutputModeOption _outputMode; + private readonly OutputModeOption _outputMode; private AutoResetEvent _closedEvent; - private OutGridViewCommand _parentCmdlet; + private readonly OutGridViewCommand _parentCmdlet; - private GraphicalHostReflectionWrapper _graphicalHostReflectionWrapper; + private readonly GraphicalHostReflectionWrapper _graphicalHostReflectionWrapper; /// /// Initializes a new instance of the OutWindowProxy class. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ScalarTypeColumnInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ScalarTypeColumnInfo.cs index b72c9b7d439..77f80c269a3 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ScalarTypeColumnInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ScalarTypeColumnInfo.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.Commands { internal class ScalarTypeColumnInfo : ColumnInfo { - private Type _type; + private readonly Type _type; internal ScalarTypeColumnInfo(Type type) : base(type.Name, type.Name) @@ -45,7 +45,7 @@ internal override object GetValue(PSObject liveObject) internal class ToStringColumnInfo : ColumnInfo { - private OutGridViewCommand _parentCmdlet; + private readonly OutGridViewCommand _parentCmdlet; internal ToStringColumnInfo(string staleObjectPropertyName, string displayName, OutGridViewCommand parentCmdlet) : base(staleObjectPropertyName, displayName) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/WriteFormatDataCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/WriteFormatDataCommand.cs index 919264ad180..457418b30fc 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/WriteFormatDataCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/WriteFormatDataCommand.cs @@ -75,7 +75,7 @@ public string LiteralPath private bool _isLiteralPath = false; - private List _typeDefinitions = new List(); + private readonly List _typeDefinitions = new List(); private bool _force; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs index e38a22ac98c..4eecbb5d859 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs @@ -276,7 +276,7 @@ private void pd_PrintPage(object sender, PrintPageEventArgs ev) /// /// Name of the printer to print to. Null means default printer. /// - private string _printerName = null; + private readonly string _printerName = null; /// /// Name of the font to use, if null the default is used. @@ -315,13 +315,13 @@ private void pd_PrintPage(object sender, PrintPageEventArgs ev) /// /// Text lines ready to print (after output cache playback). /// - private Queue _lines = new Queue(); + private readonly Queue _lines = new Queue(); /// /// Cached font object. /// private Font _printFont = null; - private WriteLineHelper _writeLineHelper; + private readonly WriteLineHelper _writeLineHelper; } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-string/Out-String.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-string/Out-String.cs index 5dcb3c4f588..e76d90af8b5 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-string/Out-String.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-string/Out-String.cs @@ -166,6 +166,6 @@ protected override void EndProcessing() /// /// Buffer used when buffering until the end. /// - private StringBuilder _buffer = new StringBuilder(); + private readonly StringBuilder _buffer = new StringBuilder(); } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs index daa870d9b1a..d917271b4fc 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetMember.cs @@ -132,7 +132,7 @@ public SwitchParameter Force private MshMemberMatchOptions _matchOptions = MshMemberMatchOptions.None; - private HybridDictionary _typesAlreadyDisplayed = new HybridDictionary(); + private readonly HybridDictionary _typesAlreadyDisplayed = new HybridDictionary(); /// /// This method implements the ProcessRecord method for get-member command. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs index 01cf6534c48..7b10beaa412 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs @@ -109,10 +109,10 @@ private void ThrowMinGreaterThanOrEqualMax(object minValue, object maxValue) #region Random generator state - private static ReaderWriterLockSlim s_runspaceGeneratorMapLock = new ReaderWriterLockSlim(); + private static readonly ReaderWriterLockSlim s_runspaceGeneratorMapLock = new ReaderWriterLockSlim(); // 1-to-1 mapping of runspaces and random number generators - private static Dictionary s_runspaceGeneratorMap = new Dictionary(); + private static readonly Dictionary s_runspaceGeneratorMap = new Dictionary(); private static void CurrentRunspace_StateChanged(object sender, RunspaceStateEventArgs e) { @@ -597,8 +597,8 @@ internal PolymorphicRandomNumberGenerator(int seed) _pseudoGenerator = new Random(seed); } - private Random _pseudoGenerator = null; - private RandomNumberGenerator _cryptographicGenerator = null; + private readonly Random _pseudoGenerator = null; + private readonly RandomNumberGenerator _cryptographicGenerator = null; /// /// Generates a random floating-point number that is greater than or equal to 0.0, and less than 1.0. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs index b7266fa1114..cd5e2ebba9a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs @@ -806,7 +806,7 @@ private ErrorRecord GetErrorNoResultsFromRemoteEnd(string commandName) return errorRecord; } - private List _commandsSkippedBecauseOfShadowing = new List(); + private readonly List _commandsSkippedBecauseOfShadowing = new List(); private void ReportSkippedCommands() { @@ -1919,9 +1919,9 @@ internal class ImplicitRemotingCodeGenerator #region Constructor and shared private data - private PSSession _remoteRunspaceInfo; + private readonly PSSession _remoteRunspaceInfo; private Guid _moduleGuid; - private InvocationInfo _invocationInfo; + private readonly InvocationInfo _invocationInfo; internal ImplicitRemotingCodeGenerator( PSSession remoteRunspaceInfo, diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs index 0ee80712123..57a3bd59653 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs @@ -271,7 +271,7 @@ protected override void EndProcessing() /// internal static class PSMarkdownOptionInfoCache { - private static ConcurrentDictionary markdownOptionInfoCache; + private static readonly ConcurrentDictionary markdownOptionInfoCache; private const string MarkdownOptionInfoVariableName = "PSMarkdownOptionInfo"; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs index 230f985c19e..4b31567ea10 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs @@ -959,7 +959,7 @@ private TextMeasureInfo CreateTextMeasureInfo(Statistics stat) /// The observed statistics keyed by property name. /// If Property is not set, then the key used will be the value of thisObject. /// - private MeasureObjectDictionary _statistics = new MeasureObjectDictionary(); + private readonly MeasureObjectDictionary _statistics = new MeasureObjectDictionary(); /// /// Whether or not a numeric conversion error occurred. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs index fd69a2011fb..dce7a31cee0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs @@ -67,7 +67,7 @@ internal CultureInfo Culture internal static readonly ObjectCommandPropertyValue NonExistingProperty = new ObjectCommandPropertyValue(); internal static readonly ObjectCommandPropertyValue ExistingNullProperty = new ObjectCommandPropertyValue(null); - private bool _caseSensitive; + private readonly bool _caseSensitive; internal CultureInfo cultureInfo = null; /// @@ -225,11 +225,11 @@ public int Compare(object first, object second) return _cultureInfo.CompareInfo.Compare(firstString, secondString, _caseSensitive ? CompareOptions.None : CompareOptions.IgnoreCase) * (_ascendingOrder ? 1 : -1); } - private CultureInfo _cultureInfo = null; + private readonly CultureInfo _cultureInfo = null; - private bool _ascendingOrder = true; + private readonly bool _ascendingOrder = true; - private bool _caseSensitive = false; + private readonly bool _caseSensitive = false; } #endregion } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs index c2ebc9261a1..7fa58dadfdb 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs @@ -529,7 +529,7 @@ internal OrderByPropertyEntry CreateOrderByPropertyEntry( #endregion Utils // list of processed parameters obtained from the Expression array - private List _mshParameterList = null; + private readonly List _mshParameterList = null; // list of unprocessed parameters obtained from the Expression array. private List _unexpandedParameterList = null; @@ -698,7 +698,7 @@ internal static OrderByPropertyComparer CreateComparer(List @@ -727,6 +727,6 @@ public int Compare(OrderByPropertyEntry lhs, OrderByPropertyEntry rhs) return result; } - private OrderByPropertyComparer _orderByPropertyComparer = null; + private readonly OrderByPropertyComparer _orderByPropertyComparer = null; } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs index bba2ac2873d..f59931d7a8e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs @@ -52,7 +52,7 @@ internal bool IsMatch(PSPropertyExpression expression) return false; } - private WildcardPattern[] _wildcardPatterns; + private readonly WildcardPattern[] _wildcardPatterns; } internal class SelectObjectExpressionParameterDefinition : CommandParameterDefinition @@ -304,8 +304,11 @@ public PSObject StreamingDequeue() } private int _streamedObjectCount; - private int _first, _last, _skip, _skipLast; - private bool _firstOrLastSpecified; + private readonly int _first; + private readonly int _last; + private int _skip; + private readonly int _skipLast; + private readonly bool _firstOrLastSpecified; } /// diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs index 957c21d465d..90d34be2ff3 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs @@ -173,7 +173,7 @@ public Encoding Encoding #region Private variables and methods // Instantiate a new instance of MailMessage - private MailMessage _mMailMessage = new MailMessage(); + private readonly MailMessage _mMailMessage = new MailMessage(); private SmtpClient _mSmtpClient = null; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandProxy.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandProxy.cs index 4a5700bdf7a..a8a9c8f194d 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandProxy.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandProxy.cs @@ -20,9 +20,9 @@ internal class ShowCommandProxy { private const string ShowCommandHelperName = "Microsoft.PowerShell.Commands.ShowCommandInternal.ShowCommandHelper"; - private ShowCommandCommand _cmdlet; + private readonly ShowCommandCommand _cmdlet; - private GraphicalHostReflectionWrapper _graphicalHostReflectionWrapper; + private readonly GraphicalHostReflectionWrapper _graphicalHostReflectionWrapper; internal ShowCommandProxy(ShowCommandCommand cmdlet) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs index 4fe5c641ff9..0f8453c503e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/StartSleepCommand.cs @@ -64,7 +64,7 @@ public void Dispose() // object used for synchronizes pipeline thread and stop thread // access to waitHandle - private object _syncObject = new object(); + private readonly object _syncObject = new object(); // this is set to true by stopProcessing private bool _stopping = false; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs index d7071a06605..cafc9e355ff 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TimeExpressionCommand.cs @@ -37,7 +37,7 @@ public sealed class MeasureCommandCommand : PSCmdlet #region private members - private System.Diagnostics.Stopwatch _stopWatch = new System.Diagnostics.Stopwatch(); + private readonly System.Diagnostics.Stopwatch _stopWatch = new System.Diagnostics.Stopwatch(); #endregion diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs index de7d2590176..75462fbaba8 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs @@ -28,7 +28,7 @@ public class UpdateTypeDataCommand : UpdateData private const string DynamicTypeSet = "DynamicTypeSet"; private const string TypeDataSet = "TypeDataSet"; - private static object s_notSpecified = new object(); + private static readonly object s_notSpecified = new object(); private static bool HasBeenSpecified(object obj) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WaitEventCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WaitEventCommand.cs index 7aeb864e2ba..77f6283f9fb 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WaitEventCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WaitEventCommand.cs @@ -60,9 +60,9 @@ public int Timeout #endregion parameters - private AutoResetEvent _eventArrived = new AutoResetEvent(false); + private readonly AutoResetEvent _eventArrived = new AutoResetEvent(false); private PSEventArgs _receivedEvent = null; - private object _receivedEventLock = new object(); + private readonly object _receivedEventLock = new object(); private WildcardPattern _matchPattern; /// diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs index 273fae835c3..ba1e69c080f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs @@ -261,9 +261,9 @@ internal BufferingStreamReader(Stream baseStream) _copyBuffer = new byte[4096]; } - private Stream _baseStream; - private MemoryStream _streamBuffer; - private byte[] _copyBuffer; + private readonly Stream _baseStream; + private readonly MemoryStream _streamBuffer; + private readonly byte[] _copyBuffer; public override bool CanRead { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs index 955786248f7..e0c60ca8f3e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertFromJsonCommand.cs @@ -27,7 +27,7 @@ public class ConvertFromJsonCommand : Cmdlet /// /// InputObjectBuffer buffers all InputObject contents available in the pipeline. /// - private List _inputObjectBuffer = new List(); + private readonly List _inputObjectBuffer = new List(); /// /// Returned data structure is a Hashtable instead a CustomPSObject. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs index 92e67f5681a..84a79ba3b23 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs @@ -93,7 +93,7 @@ protected override void BeginProcessing() } } - private List _inputObjects = new List(); + private readonly List _inputObjects = new List(); /// /// Caching the input objects for the command. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs index 5cb4f2b4fde..226a981f8a2 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.Commands internal class WebProxy : IWebProxy { private ICredentials _credentials; - private Uri _proxyAddress; + private readonly Uri _proxyAddress; internal WebProxy(Uri address) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs index 58d63c36ca3..7d2eaefcfc1 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs @@ -24,9 +24,9 @@ internal class WebResponseContentMemoryStream : MemoryStream { #region Data - private Stream _originalStreamToProxy; + private readonly Stream _originalStreamToProxy; private bool _isInitialized = false; - private Cmdlet _ownerCmdlet; + private readonly Cmdlet _ownerCmdlet; #endregion diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs index 9d4264b8b18..ed8542b5840 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs @@ -647,7 +647,7 @@ internal class ImportXmlHelper : IDisposable /// Reference to cmdlet which is using this helper class. /// private readonly PSCmdlet _cmdlet; - private bool _isLiteralPath; + private readonly bool _isLiteralPath; internal ImportXmlHelper(string fileName, PSCmdlet cmdlet, bool isLiteralPath) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs index 60bbe552e50..d479b4d32c0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs @@ -88,7 +88,7 @@ public override void Write(string output) } } - private StringBuilder _cachedWrite = new StringBuilder(); + private readonly StringBuilder _cachedWrite = new StringBuilder(); /// /// Sends the given output string to the host for processing. @@ -116,6 +116,6 @@ public override void WriteLine(string output) /// /// The host interface to write the debug line to. /// - private InternalHostUserInterface _ui; + private readonly InternalHostUserInterface _ui; } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs index 04e35a9018d..d862750a1cf 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs @@ -540,9 +540,9 @@ private static ErrorRecord ConvertToErrorRecord(object obj) return result; } - private TraceListenerCommandBase _cmdlet; - private bool _writeError; + private readonly TraceListenerCommandBase _cmdlet; + private readonly bool _writeError; private bool _isOpen = true; - private Collection _matchingSources = new Collection(); + private readonly Collection _matchingSources = new Collection(); } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs index 3eecdd51cba..a58af1b7f87 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs @@ -597,7 +597,7 @@ protected void ClearStoredState() _storedTraceSourceState.Clear(); } - private Dictionary>> _storedTraceSourceState = + private readonly Dictionary>> _storedTraceSourceState = new Dictionary>>(); #endregion stored state