diff --git a/.editorconfig b/.editorconfig
index a00fd02dd66..5e367c0750b 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -135,6 +135,21 @@ csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
+# Force rules
+
+# IDE0044: Add readonly modifier
+dotnet_style_readonly_field = true:error
+# IDE1006: Naming Styles
+dotnet_diagnostic.IDE1006.severity = error
+# IDE0003: Remove qualification
+dotnet_style_qualification_for_method = false:none
+# IDE0003: Remove qualification
+dotnet_style_qualification_for_field = false:none
+# IDE0003: Remove qualification
+dotnet_style_qualification_for_property = false:none
+# IDE0003: Remove qualification
+dotnet_style_qualification_for_event = false:none
+
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
diff --git a/PowerShell.sln b/PowerShell.sln
index b164361d7d2..cf90983621d 100644
--- a/PowerShell.sln
+++ b/PowerShell.sln
@@ -1,7 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-# https://github.com/dotnet/project-system/blob/master/docs/opening-with-new-project-system.md#project-type-guids
-VisualStudioVersion = 15.0.26730.12
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "powershell-win-core", "src\powershell-win-core\powershell-win-core.csproj", "{8359D422-E0C4-4A0D-94EB-3C9DD16B7932}"
EndProject
@@ -42,6 +41,11 @@ EndProject
#
# 73EA0BE6-C0C5-4B56-A5AA-DADA4C01D690 - powershell-unix
# Only Linux is valid, all configurations mapped to Linux
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D0361BC1-7403-4662-B918-215480B5CD17}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CodeCoverage|Any CPU = CodeCoverage|Any CPU
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs
index 1e21b781742..98571d475ea 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs
@@ -559,14 +559,14 @@ private void Cleanup()
///
/// Event to notify ps thread that more action is available.
///
- private ManualResetEventSlim moreActionEvent;
+ private readonly ManualResetEventSlim moreActionEvent;
///
/// The following is the definition of action queue.
/// The queue holding all actions to be executed in the context of either
/// ProcessRecord or EndProcessing.
///
- private ConcurrentQueue actionQueue;
+ private readonly ConcurrentQueue actionQueue;
///
/// Lock object.
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs
index 345b27bb48b..0ac7ac5c1cb 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs
@@ -126,7 +126,7 @@ protected virtual void Block()
///
/// Action completed event.
///
- private ManualResetEventSlim completeEvent;
+ private readonly ManualResetEventSlim completeEvent;
///
/// Response result.
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCmdletModuleInitialize.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCmdletModuleInitialize.cs
index 72f6f0e28e4..a931ca66f85 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCmdletModuleInitialize.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCmdletModuleInitialize.cs
@@ -79,21 +79,21 @@ internal CimCmdletAliasEntry(string name, string value)
///
internal string Name { get { return this._name; } }
- private string _name;
+ private readonly string _name;
///
/// The string defining real cmdlet name.
///
internal string Value { get { return this._value; } }
- private string _value = string.Empty;
+ private readonly string _value = string.Empty;
///
/// The string defining real cmdlet name.
///
internal ScopedItemOptions Options { get { return this._options; } }
- private ScopedItemOptions _options = ScopedItemOptions.AllScope | ScopedItemOptions.ReadOnly;
+ private readonly ScopedItemOptions _options = ScopedItemOptions.AllScope | ScopedItemOptions.ReadOnly;
}
///
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs
index 6420fe28909..6b1395e3fd5 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs
@@ -261,7 +261,7 @@ internal ParameterBinder(
///
/// Parameter names list.
///
- private List parameterNamesList = new List();
+ private readonly List parameterNamesList = new List();
///
///
@@ -275,7 +275,7 @@ internal ParameterBinder(
///
/// Parameter names list before begin process.
///
- private List parameterNamesListAtBeginProcess = new List();
+ private readonly List parameterNamesListAtBeginProcess = new List();
///
///
@@ -676,7 +676,7 @@ protected virtual void DisposeInternal()
///
/// Parameter binder used to resolve parameter set name.
///
- private ParameterBinder parameterBinder;
+ private readonly ParameterBinder parameterBinder;
///
///
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs
index a3826487e24..1d053a2b0dd 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs
@@ -68,7 +68,7 @@ internal string MethodName
get { return methodName; }
}
- private string methodName;
+ private readonly string methodName;
///
///
@@ -82,7 +82,7 @@ internal string PropertyName
get { return propertyName; }
}
- private string propertyName;
+ private readonly string propertyName;
///
///
@@ -96,7 +96,7 @@ internal string QualifierName
get { return qualifierName; }
}
- private string qualifierName;
+ private readonly string qualifierName;
}
///
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs
index fd44d922009..198c86e96af 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs
@@ -53,7 +53,7 @@ public Exception Exception
}
}
- private Exception exception;
+ private readonly Exception exception;
///
///
@@ -124,7 +124,7 @@ public CimIndicationEventInstanceEventArgs(CimSubscriptionResult result)
/// subscription result
///
///
- private CimSubscriptionResult result;
+ private readonly CimSubscriptionResult result;
}
///
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs
index 74f4a571dd2..801939e5c48 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs
@@ -57,7 +57,7 @@ internal string MethodName
}
}
- private string methodName;
+ private readonly string methodName;
///
/// parameters collection
@@ -70,7 +70,7 @@ internal CimMethodParametersCollection ParametersCollection
}
}
- private CimMethodParametersCollection collection;
+ private readonly CimMethodParametersCollection collection;
}
///
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs
index 4d4ff5d6ec5..98fb4ed3fc8 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs
@@ -129,12 +129,12 @@ public string Message
}
}
- private string message;
+ private readonly string message;
///
/// Prompt type -Normal or Critical.
///
- private CimPromptType prompt;
+ private readonly CimPromptType prompt;
#endregion
}
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
index 5dee76e5f3c..ca61e4403d4 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
@@ -56,7 +56,7 @@ public CimSubscriptionResult Result
}
}
- private CimSubscriptionResult result;
+ private readonly CimSubscriptionResult result;
///
/// Constructor
@@ -90,7 +90,7 @@ public Exception Exception
}
}
- private Exception exception;
+ private readonly Exception exception;
///
/// Constructor
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs
index 55cf540c0e8..f357ccee1f5 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs
@@ -51,7 +51,7 @@ internal object ErrorSource
}
}
- private object errorSource;
+ private readonly object errorSource;
}
#endregion
@@ -352,17 +352,17 @@ protected CimSession CurrentSession
}
}
- private CimSession session;
+ private readonly CimSession session;
///
/// Async operation that can be observed.
///
- private IObservable
///
- private Dictionary> curCimSessionsByName;
+ private readonly Dictionary> curCimSessionsByName;
///
///
/// Dictionary used to holds all CimSessions in current runspace by computer name.
///
///
- private Dictionary> curCimSessionsByComputerName;
+ private readonly Dictionary> curCimSessionsByComputerName;
///
///
/// Dictionary used to holds all CimSessions in current runspace by instance ID.
///
///
- private Dictionary curCimSessionsByInstanceId;
+ private readonly Dictionary curCimSessionsByInstanceId;
///
///
/// Dictionary used to holds all CimSessions in current runspace by session id.
///
///
- private Dictionary curCimSessionsById;
+ private readonly Dictionary curCimSessionsById;
///
///
/// Dictionary used to link CimSession object with PSObject.
///
///
- private Dictionary curCimSessionWrapper;
+ private readonly Dictionary curCimSessionWrapper;
#endregion
@@ -934,7 +934,7 @@ internal CimSessionWrapper CimSessionWrapper
}
}
- private CimSessionWrapper cimSessionWrapper;
+ private readonly CimSessionWrapper cimSessionWrapper;
}
///
@@ -1052,7 +1052,7 @@ public void ProcessRemainActions(CmdletOperationBase cmdletOperation)
/// object.
///
///
- private CimTestSession cimTestSession;
+ private readonly CimTestSession cimTestSession;
#endregion // private members
#region IDisposable
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs
index a8e4fcd977f..99e36083ff3 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs
@@ -218,7 +218,7 @@ internal class CimSessionProxy : IDisposable
/// then call Dispose on it.
///
///
- private static Dictionary temporarySessionCache = new Dictionary();
+ private static readonly Dictionary temporarySessionCache = new Dictionary();
///
///
@@ -1065,7 +1065,7 @@ private static void AddShowComputerNameMarker(object o)
}
#if DEBUG
- private static bool isCliXmlTestabilityHookActive = GetIsCliXmlTestabilityHookActive();
+ private static readonly bool isCliXmlTestabilityHookActive = GetIsCliXmlTestabilityHookActive();
private static bool GetIsCliXmlTestabilityHookActive()
{
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CDXML_CLIXML_TEST"));
@@ -1567,7 +1567,7 @@ private bool Completed
///
/// The current operation parameters.
///
- private Hashtable operationParameters = new Hashtable();
+ private readonly Hashtable operationParameters = new Hashtable();
///
/// Handler used to cancel operation.
@@ -1675,7 +1675,7 @@ internal IObjectPreProcess ObjectPreProcess
/// created to handle the "default" session, in cases where cmdlets are invoked without
/// ComputerName and/or CimSession parameters.
///
- private bool isDefaultSession;
+ private readonly bool isDefaultSession;
#endregion
@@ -2259,7 +2259,7 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args)
#region private members
- private CimNewCimInstance newCimInstance = null;
+ private readonly CimNewCimInstance newCimInstance = null;
internal CimNewCimInstance NewCimInstanceOperation
{
get
@@ -2348,7 +2348,7 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args)
///
/// Ture indicates need to output the modified result.
///
- private bool passThru = false;
+ private readonly bool passThru = false;
#endregion
}
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs
index d55532e805e..674eadfbe66 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs
@@ -51,7 +51,7 @@ internal IDictionary Property
}
}
- private IDictionary property;
+ private readonly IDictionary property;
///
/// parameter set name
@@ -64,7 +64,7 @@ internal string ParameterSetName
}
}
- private string parameterSetName;
+ private readonly string parameterSetName;
///
/// PassThru value
@@ -77,7 +77,7 @@ internal bool PassThru
}
}
- private bool passThru;
+ private readonly bool passThru;
}
///
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs
index fbd780450ab..9d367877a4c 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs
@@ -375,7 +375,7 @@ public override void Execute(CmdletOperationBase cmdlet)
/// Error instance
///
///
- private CimInstance error;
+ private readonly CimInstance error;
internal CimInstance Error
{
@@ -398,7 +398,7 @@ internal Exception Exception
}
}
- private Exception exception;
+ private readonly Exception exception;
///
///
@@ -406,7 +406,7 @@ internal Exception Exception
/// the information while issuing the current operation
///
///
- private InvocationContext invocationContext;
+ private readonly InvocationContext invocationContext;
internal InvocationContext CimInvocationContext
{
@@ -419,7 +419,7 @@ internal InvocationContext CimInvocationContext
///
///
///
- private CimResultContext cimResultContext;
+ private readonly CimResultContext cimResultContext;
internal CimResultContext ResultContext
{
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs
index b351813c4d4..9a556b68c5e 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs
@@ -22,12 +22,12 @@ internal sealed class CimWriteMessage : CimBaseAction
///
/// Channel id.
///
- private UInt32 channel;
+ private readonly UInt32 channel;
///
/// Message to write to the channel.
///
- private string message;
+ private readonly string message;
#endregion
#region Properties
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs
index 720f5537d2b..e6651ed94ff 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs
@@ -92,32 +92,32 @@ public override void Execute(CmdletOperationBase cmdlet)
///
/// Activity of the given activity.
///
- private string activity;
+ private readonly string activity;
///
/// Activity identifier of the given activity.
///
- private int activityID;
+ private readonly int activityID;
///
/// Current operation text of the given activity.
///
- private string currentOperation;
+ private readonly string currentOperation;
///
/// Status description of the given activity.
///
- private string statusDescription;
+ private readonly string statusDescription;
///
/// Percentage completed of the given activity.
///
- private UInt32 percentageCompleted;
+ private readonly UInt32 percentageCompleted;
///
/// How many seconds remained for the given activity.
///
- private UInt32 secondsRemaining;
+ private readonly UInt32 secondsRemaining;
internal string Activity
{
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs
index b1ef21600ed..9a31f1c318e 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs
@@ -47,7 +47,7 @@ internal object Result
}
}
- private object result;
+ private readonly object result;
#endregion
}
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
index 648f6cfb327..8e3cf15df58 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
@@ -188,7 +188,7 @@ public override void WriteObject(object sendToPipeline, bool enumerateCollection
#region private methods
- private CimRemoveCimInstance removeCimInstance;
+ private readonly CimRemoveCimInstance removeCimInstance;
private const string cimRemoveCimInstanceParameterName = @"cimRemoveCimInstance";
@@ -268,7 +268,7 @@ public override void WriteObject(object sendToPipeline, bool enumerateCollection
#region private methods
- private CimSetCimInstance setCimInstance;
+ private readonly CimSetCimInstance setCimInstance;
private const string theCimSetCimInstanceParameterName = @"theCimSetCimInstance";
@@ -331,7 +331,7 @@ public override void WriteObject(object sendToPipeline, bool enumerateCollection
#region private methods
- private CimInvokeCimMethod cimInvokeCimMethod;
+ private readonly CimInvokeCimMethod cimInvokeCimMethod;
private const string theCimInvokeCimMethodParameterName = @"theCimInvokeCimMethod";
@@ -392,7 +392,7 @@ public override void WriteObject(object sendToPipeline, XOperationContextBase co
#region private methods
- private CimNewSession cimNewSession;
+ private readonly CimNewSession cimNewSession;
private const string theCimNewSessionParameterName = @"theCimNewSession";
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs
index 06754aae168..13f3d17b689 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs
@@ -318,7 +318,7 @@ CimGetAssociatedInstance CreateOperationAgent()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameComputerName, new HashSet {
@@ -347,7 +347,7 @@ CimGetAssociatedInstance CreateOperationAgent()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.SessionSetName, new ParameterSetEntry(2, false) },
{ CimBaseCommand.ComputerSetName, new ParameterSetEntry(1, true) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs
index 0c2032720a0..d695f9a0431 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs
@@ -291,7 +291,7 @@ CimGetCimClass CreateOperationAgent()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameCimSession, new HashSet {
@@ -309,7 +309,7 @@ CimGetCimClass CreateOperationAgent()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.SessionSetName, new ParameterSetEntry(1) },
{ CimBaseCommand.ComputerSetName, new ParameterSetEntry(0, true) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs
index ba5f6125a7f..ab823258da9 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs
@@ -552,7 +552,7 @@ private void CheckArgument()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameCimSession, new HashSet {
@@ -656,7 +656,7 @@ private void CheckArgument()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.CimInstanceComputerSet, new ParameterSetEntry(1) },
{ CimBaseCommand.CimInstanceSessionSet, new ParameterSetEntry(2) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimSessionCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimSessionCommand.cs
index 459c777c817..8355822d2e2 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimSessionCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimSessionCommand.cs
@@ -173,7 +173,7 @@ protected override void ProcessRecord()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameComputerName, new HashSet {
@@ -200,7 +200,7 @@ protected override void ProcessRecord()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.ComputerNameSet, new ParameterSetEntry(0, true) },
{ CimBaseCommand.SessionIdSet, new ParameterSetEntry(1) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs
index b4d58032739..e2bbc81eaec 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs
@@ -473,7 +473,7 @@ private void CheckArgument()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameClassName, new HashSet {
@@ -560,7 +560,7 @@ private void CheckArgument()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.ClassNameComputerSet, new ParameterSetEntry(2, true) },
{ CimBaseCommand.ResourceUriSessionSet, new ParameterSetEntry(3) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs
index 444dcd1f32c..f22093d161f 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs
@@ -440,7 +440,7 @@ private void CheckArgument()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameClassName, new HashSet {
@@ -503,7 +503,7 @@ private void CheckArgument()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.ClassNameSessionSet, new ParameterSetEntry(2) },
{ CimBaseCommand.ClassNameComputerSet, new ParameterSetEntry(1, true) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs
index d53403d5e81..4b404457328 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs
@@ -709,7 +709,7 @@ internal WSManSessionOptions CreateWSMANSessionOptions()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameNoEncryption, new HashSet {
@@ -810,7 +810,7 @@ internal WSManSessionOptions CreateWSMANSessionOptions()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.ProtocolNameParameterSet, new ParameterSetEntry(1, true) },
{ CimBaseCommand.DcomParameterSet, new ParameterSetEntry(0) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs
index e34ad952d50..3b713e1ffee 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs
@@ -291,7 +291,7 @@ private void CheckArgument()
///
/// Parameter binder used to resolve parameter set name.
///
- private ParameterBinder parameterBinder = new ParameterBinder(
+ private readonly ParameterBinder parameterBinder = new ParameterBinder(
parameters, parameterSets);
///
@@ -319,7 +319,7 @@ private void SetParameter(object value, string parameterName)
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameClassName, new HashSet {
@@ -356,7 +356,7 @@ private void SetParameter(object value, string parameterName)
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.QueryExpressionSessionSet, new ParameterSetEntry(2) },
{ CimBaseCommand.QueryExpressionComputerSet, new ParameterSetEntry(1) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs
index c7f2ab4c6a3..ab94a7fca73 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs
@@ -322,7 +322,7 @@ CimRemoveCimInstance CreateOperationAgent()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameCimSession, new HashSet {
@@ -371,7 +371,7 @@ CimRemoveCimInstance CreateOperationAgent()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.CimInstanceComputerSet, new ParameterSetEntry(1, true) },
{ CimBaseCommand.CimInstanceSessionSet, new ParameterSetEntry(2) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimSessionCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimSessionCommand.cs
index 20fae29b593..deca6cc385d 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimSessionCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimSessionCommand.cs
@@ -199,7 +199,7 @@ protected override void ProcessRecord()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameCimSession, new HashSet {
@@ -231,7 +231,7 @@ protected override void ProcessRecord()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.CimSessionSet, new ParameterSetEntry(1, true) },
{ CimBaseCommand.ComputerNameSet, new ParameterSetEntry(1) },
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs
index 714a192081a..507dcd61097 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs
@@ -380,7 +380,7 @@ CimSetCimInstance CreateOperationAgent()
///
/// Static parameter definition entries.
///
- static Dictionary> parameters = new Dictionary>
+ static readonly Dictionary> parameters = new Dictionary>
{
{
nameCimSession, new HashSet {
@@ -437,7 +437,7 @@ CimSetCimInstance CreateOperationAgent()
///
/// Static parameter set entries.
///
- static Dictionary parameterSets = new Dictionary
+ static readonly Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.QuerySessionSet, new ParameterSetEntry(3) },
{ CimBaseCommand.QueryComputerSet, new ParameterSetEntry(2) },
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSample.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSample.cs
index 3a7af308f29..b7d487701b5 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSample.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSample.cs
@@ -193,6 +193,6 @@ public PerformanceCounterSample[] CounterSamples
private PerformanceCounterSample[] _counterSamples = null;
- private ResourceManager _resourceMgr = null;
+ private readonly ResourceManager _resourceMgr = null;
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSet.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSet.cs
index c1474ec4209..cece3bffb9b 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSet.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/CounterSet.cs
@@ -45,7 +45,7 @@ public string CounterSetName
}
}
- private string _counterSetName = string.Empty;
+ private readonly string _counterSetName = string.Empty;
public string MachineName
{
@@ -55,7 +55,7 @@ public string MachineName
}
}
- private string _machineName = ".";
+ private readonly string _machineName = ".";
public PerformanceCounterCategoryType CounterSetType
{
@@ -65,7 +65,7 @@ public PerformanceCounterCategoryType CounterSetType
}
}
- private PerformanceCounterCategoryType _counterSetType;
+ private readonly PerformanceCounterCategoryType _counterSetType;
public string Description
{
@@ -75,7 +75,7 @@ public string Description
}
}
- private string _description = string.Empty;
+ private readonly string _description = string.Empty;
internal Dictionary CounterInstanceMapping
{
@@ -85,7 +85,7 @@ internal Dictionary CounterInstanceMapping
}
}
- private Dictionary _counterInstanceMapping;
+ private readonly Dictionary _counterInstanceMapping;
public StringCollection Paths
{
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
index 566ae6d1d22..8afaeaeff40 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
@@ -92,7 +92,7 @@ public string[] Counter
@"\physicaldisk(_total)\current disk queue length"};
private bool _defaultCounters = true;
- private List _accumulatedCounters = new List();
+ private readonly List _accumulatedCounters = new List();
//
// SampleInterval parameter.
@@ -178,7 +178,7 @@ public string[] ComputerName
private PdhHelper _pdhHelper = null;
- private EventWaitHandle _cancelEventArrived = new EventWaitHandle(false, EventResetMode.ManualReset);
+ private readonly EventWaitHandle _cancelEventArrived = new EventWaitHandle(false, EventResetMode.ManualReset);
// Culture identifier(s)
private const string FrenchCultureId = "fr-FR";
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
index 41829598482..9e0e9ceed2e 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
@@ -396,14 +396,14 @@ public SwitchParameter Oldest
// Other private members and constants
//
private ResourceManager _resourceMgr = null;
- private Dictionary _providersByLogMap = new Dictionary();
+ private readonly Dictionary _providersByLogMap = new Dictionary();
private StringCollection _logNamesMatchingWildcard = null;
- private StringCollection _resolvedPaths = new StringCollection();
+ private readonly StringCollection _resolvedPaths = new StringCollection();
- private List _accumulatedLogNames = new List();
- private List _accumulatedProviderNames = new List();
- private List _accumulatedFileNames = new List();
+ private readonly List _accumulatedLogNames = new List();
+ private readonly List _accumulatedProviderNames = new List();
+ private readonly List _accumulatedFileNames = new List();
private const uint MAX_EVENT_BATCH = 100;
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs
index 1c0acb7f45a..54ed500583b 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs
@@ -27,7 +27,7 @@ public sealed class NewWinEventCommand : PSCmdlet
private const string TemplateTag = "template";
private const string DataTag = "data";
- private ResourceManager _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();
+ private readonly ResourceManager _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();
///
/// ProviderName.
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs
index c6c1ddd8be8..66cafb03371 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs
@@ -423,7 +423,7 @@ public void Dispose()
//
// m_ConsumerPathToHandleAndInstanceMap map is used for reading counter date (live or from files).
//
- private Dictionary _consumerPathToHandleAndInstanceMap = new Dictionary();
+ private readonly Dictionary _consumerPathToHandleAndInstanceMap = new Dictionary();
///
/// A helper reading in a Unicode string with embedded NULLs and splitting it into a StringCollection.
diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/QueryJobBase.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/QueryJobBase.cs
index 8ee336de383..b52c23c3dd4 100644
--- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/QueryJobBase.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/QueryJobBase.cs
@@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
///
internal abstract class QueryJobBase : CimChildJobBase
{
- private CimQuery _cimQuery;
+ private readonly CimQuery _cimQuery;
internal QueryJobBase(CimJobContext jobContext, CimQuery cimQuery)
: base(jobContext)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs
index 578b4a7efde..1a59fb55ff5 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs
@@ -319,7 +319,7 @@ public Int16 Delay
///
/// The indicator to use when show progress.
///
- private string[] _indicator = { "|", "/", "-", "\\" };
+ private readonly string[] _indicator = { "|", "/", "-", "\\" };
///
/// The activity id.
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs
index 14f8a207ae5..640596e2c4f 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs
@@ -85,7 +85,7 @@ private class MiscInfoGroup
#endregion Static Data and Constants
#region Instance Data
- private string _machineName = localMachineName; // we might need to have cmdlet work on another machine
+ private readonly string _machineName = localMachineName; // we might need to have cmdlet work on another machine
///
/// Collection of property names from the Property parameter,
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
index 2ba50c23459..ccdec01cc80 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
@@ -108,7 +108,7 @@ public virtual Process[] InputObject
// We use a Dictionary to optimize the check whether the object
// is already in the list.
private List _matchingProcesses = new List();
- private Dictionary _keys = new Dictionary();
+ private readonly Dictionary _keys = new Dictionary();
///
/// Retrieve the list of all processes matching the Name, Id
@@ -955,7 +955,7 @@ private void myProcess_Exited(object sender, System.EventArgs e)
#region Overrides
- private List _processList = new List();
+ private readonly List _processList = new List();
// Wait handle which is used by thread to sleep.
private ManualResetEvent _waitHandle;
@@ -2606,7 +2606,7 @@ internal class ProcessCollection
/// JobObjectHandle is a reference to the job object used to track
/// the child processes created by the main process hosted by the Start-Process cmdlet.
///
- private Microsoft.PowerShell.Commands.SafeJobHandle _jobObjectHandle;
+ private readonly Microsoft.PowerShell.Commands.SafeJobHandle _jobObjectHandle;
///
/// ProcessCollection constructor.
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs
index bcb7330c674..4c8a7c36c7b 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs
@@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.Commands
[Alias("scb")]
public class SetClipboardCommand : PSCmdlet
{
- private List _contentList = new List();
+ private readonly List _contentList = new List();
///
/// Property that sets clipboard content.
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
index 397ca036151..a3b0f7e15c8 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
@@ -852,7 +852,7 @@ protected override void ProcessRecord()
///
internal class ExportCsvHelper : IDisposable
{
- private char _delimiter;
+ private readonly char _delimiter;
readonly private BaseCsvWritingCommand.QuoteKind _quoteKind;
readonly private HashSet _quoteFields;
readonly private 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 91985bd17c7..6cab64a4d29 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 8ae81bedd24..2945c94612e 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
@@ -325,7 +325,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)
{
@@ -351,7 +351,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 49d41d8ce3e..97b0dace7e9 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
@@ -27,15 +27,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 5616a7fa436..84d2f3f2dd5 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 91955c0f26c..d60fccadb2f 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs
@@ -108,10 +108,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)
{
@@ -596,8 +596,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 61b71fe8f45..7fbf1d24e87 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs
@@ -793,7 +793,7 @@ private ErrorRecord GetErrorNoResultsFromRemoteEnd(string commandName)
return errorRecord;
}
- private List _commandsSkippedBecauseOfShadowing = new List();
+ private readonly List _commandsSkippedBecauseOfShadowing = new List();
private void ReportSkippedCommands()
{
if (_commandsSkippedBecauseOfShadowing.Count != 0)
@@ -1904,9 +1904,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 d6cecf471bc..47e1175b8b0 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";
static PSMarkdownOptionInfoCache()
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 2ef311e38f3..6e3df0d6326 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs
@@ -960,7 +960,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 e5405172bee..73c52752443 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 25da2e8025f..b6243fe0447 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs
@@ -159,7 +159,7 @@ public sealed class SendMailMessage : PSCmdlet
#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 817c4306b44..d83e8cf2dda 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)
{
return !System.Object.ReferenceEquals(obj, s_notSpecified);
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 fc0921d3c63..88bcfd6241c 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 6c191fcb6e9..7265df7f7cc 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
@@ -91,7 +91,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 c1df3aa0bf5..98fb5b574da 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 8736965fd61..ea25082f72e 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs
@@ -633,7 +633,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 fc91cec91c0..3b3e05042a6 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs
@@ -90,7 +90,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.
@@ -119,6 +119,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 c7668903ed4..a3f23a2f9e4 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
diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs
index 3b9d73c0f4f..c73d4f42f67 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs
@@ -19,10 +19,10 @@ internal sealed class PropVariant : IDisposable
{
// This is actually a VarEnum value, but the VarEnum type requires 4 bytes instead of the expected 2.
[FieldOffset(0)]
- ushort _valueType;
+ readonly ushort _valueType;
[FieldOffset(8)]
- IntPtr _ptr;
+ readonly IntPtr _ptr;
///
/// Set a string value.
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
index 9907e43c4b0..64eb9041f44 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
@@ -1408,13 +1408,13 @@ private bool CollectArgs(string[] args, ref int i)
private bool _sshServerMode;
private bool _showVersion;
private string _configurationName;
- private PSHostUserInterface _hostUI;
+ private readonly PSHostUserInterface _hostUI;
private bool _showHelp;
private bool _showExtendedHelp;
private bool _showBanner = true;
private bool _noInteractive;
- private string _bannerText;
- private string _helpText;
+ private readonly string _bannerText;
+ private readonly string _helpText;
private bool _abortStartup;
private bool _skipUserInit;
private string _customPipeName;
@@ -1429,7 +1429,7 @@ private bool CollectArgs(string[] args, ref int i)
private Serialization.DataFormat _outFormat = Serialization.DataFormat.Text;
private bool _outputFormatSpecified = false;
private Serialization.DataFormat _inFormat = Serialization.DataFormat.Text;
- private Collection _collectedArgs = new Collection();
+ private readonly Collection _collectedArgs = new Collection();
private string _file;
private string _executionPolicy;
private string _workingDirectory;
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
index 8d3eb856bd0..d414a7a0f64 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
@@ -3267,7 +3267,7 @@ internal enum CHAR_INFO_Attributes : uint
}
[TraceSourceAttribute("ConsoleControl", "Console control methods")]
- private static PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleControl", "Console control methods");
+ private static readonly PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleControl", "Console control methods");
#endif
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
index eaa0d3d43d9..99a68698e47 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
@@ -731,7 +731,7 @@ internal LocalRunspace LocalRunspace
public class ConsoleColorProxy
{
- private ConsoleHostUserInterface _ui;
+ private readonly ConsoleHostUserInterface _ui;
public ConsoleColorProxy(ConsoleHostUserInterface ui)
{
@@ -2840,12 +2840,12 @@ private string EvaluateDebugPrompt()
return promptString;
}
- private ConsoleHost _parent;
- private bool _isNested;
+ private readonly ConsoleHost _parent;
+ private readonly bool _isNested;
private bool _shouldExit;
- private Executor _exec;
- private Executor _promptExec;
- private object _syncObject = new object();
+ private readonly Executor _exec;
+ private readonly Executor _promptExec;
+ private readonly object _syncObject = new object();
private bool _isRunspacePushed = false;
private bool _runspacePopped = false;
@@ -2854,7 +2854,7 @@ private string EvaluateDebugPrompt()
// threadsafety guaranteed by enclosing class
- private static Stack s_instanceStack = new Stack();
+ private static readonly Stack s_instanceStack = new Stack();
}
[Serializable]
@@ -2909,7 +2909,7 @@ private class ConsoleHostStartupException : Exception
// Set to Unknown so that we avoid saving/restoring the console mode if we don't have a console.
private ConsoleControl.ConsoleModes _savedConsoleMode = ConsoleControl.ConsoleModes.Unknown;
- private ConsoleControl.ConsoleModes _initialConsoleMode = ConsoleControl.ConsoleModes.Unknown;
+ private readonly ConsoleControl.ConsoleModes _initialConsoleMode = ConsoleControl.ConsoleModes.Unknown;
#endif
private Thread _breakHandlerThread;
private bool _isDisposed;
@@ -2918,7 +2918,7 @@ private class ConsoleHostStartupException : Exception
internal Lazy ConsoleIn { get; } = new Lazy(() => Console.In);
private string _savedWindowTitle = string.Empty;
- private Version _ver = PSVersionInfo.PSVersion;
+ private readonly Version _ver = PSVersionInfo.PSVersion;
private int _exitCodeFromRunspace;
private bool _noExit = true;
private bool _setShouldExitCalled;
@@ -2938,7 +2938,7 @@ private class ConsoleHostStartupException : Exception
private bool _shouldEndSession;
private int _beginApplicationNotifyCount;
- private ConsoleTextWriter _consoleWriter;
+ private readonly ConsoleTextWriter _consoleWriter;
private WrappedSerializer _outputSerializer;
private WrappedSerializer _errorSerializer;
private bool _displayDebuggerBanner;
@@ -2954,11 +2954,10 @@ private class ConsoleHostStartupException : Exception
internal static InitialSessionState DefaultInitialSessionState;
[TraceSource("ConsoleHost", "ConsoleHost subclass of S.M.A.PSHost")]
- private static
- PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHost", "ConsoleHost subclass of S.M.A.PSHost");
+ private static readonly PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHost", "ConsoleHost subclass of S.M.A.PSHost");
[TraceSource("ConsoleHostRunspaceInit", "Initialization code for ConsoleHost's Runspace")]
- private static PSTraceSource s_runspaceInitTracer =
+ private static readonly PSTraceSource s_runspaceInitTracer =
PSTraceSource.GetTracer("ConsoleHostRunspaceInit", "Initialization code for ConsoleHost's Runspace", false);
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
index c1487dead65..4b3aa90d153 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
@@ -1317,17 +1317,16 @@ private static
#endregion helpers
- private ConsoleColor defaultForeground = ConsoleColor.Gray;
+ private readonly ConsoleColor defaultForeground = ConsoleColor.Gray;
- private ConsoleColor defaultBackground = ConsoleColor.Black;
+ private readonly ConsoleColor defaultBackground = ConsoleColor.Black;
- private ConsoleHostUserInterface parent = null;
+ private readonly ConsoleHostUserInterface parent = null;
private ConsoleControl.KEY_EVENT_RECORD cachedKeyEvent;
[TraceSourceAttribute("ConsoleHostRawUserInterface", "Console host's subclass of S.M.A.Host.RawConsole")]
- private static
- PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleHostRawUserInterface", "Console host's subclass of S.M.A.Host.RawConsole");
+ private static readonly PSTraceSource tracer = PSTraceSource.GetTracer("ConsoleHostRawUserInterface", "Console host's subclass of S.M.A.Host.RawConsole");
}
} // namespace
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostTranscript.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostTranscript.cs
index fd1b91574b4..0931abbf1cd 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostTranscript.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostTranscript.cs
@@ -61,7 +61,7 @@ internal void StartTranscribing(string transcriptFilename, bool shouldAppend)
}
}
*/
- private string _transcriptFileName = string.Empty;
+ private readonly string _transcriptFileName = string.Empty;
internal string StopTranscribing()
{
@@ -127,7 +127,7 @@ internal void WriteToTranscript(ReadOnlySpan text, bool newLine)
}
private StreamWriter _transcriptionWriter;
- private object _transcriptionStateLock = new object();
+ private readonly object _transcriptionStateLock = new object();
}
} // namespace
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs
index 402a3a19a25..593f78aaf33 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs
@@ -37,7 +37,7 @@ internal partial class ConsoleHostUserInterface : System.Management.Automation.H
///
/// This is a test hook for programmatically reading and writing ConsoleHost I/O.
///
- private static PSHostUserInterface s_h = null;
+ private static readonly PSHostUserInterface s_h = null;
///
/// Return true if the console supports a VT100 like virtual terminal.
@@ -2174,7 +2174,7 @@ private bool TryInvokeUserDefinedReadLine(out string input)
// used to serialize access to instance data
- private object _instanceLock = new object();
+ private readonly object _instanceLock = new object();
// If this is true, class throws on read or prompt method which require
// access to console.
@@ -2198,16 +2198,15 @@ internal void HandleThrowOnReadAndPrompt()
// this is a test hook for the ConsoleInteractiveTestTool, which sets this field to true.
- private bool _isInteractiveTestToolListening;
+ private readonly bool _isInteractiveTestToolListening;
// This instance data is "read-only" and need not have access serialized.
- private ConsoleHostRawUserInterface _rawui;
- private ConsoleHost _parent;
+ private readonly ConsoleHostRawUserInterface _rawui;
+ private readonly ConsoleHost _parent;
[TraceSourceAttribute("ConsoleHostUserInterface", "Console host's subclass of S.M.A.Host.Console")]
- private static
- PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHostUserInterface", "Console host's subclass of S.M.A.Host.Console");
+ private static readonly PSTraceSource s_tracer = PSTraceSource.GetTracer("ConsoleHostUserInterface", "Console host's subclass of S.M.A.Host.Console");
}
} // namespace
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleTextWriter.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleTextWriter.cs
index c875bc0c506..2acb7ab3061 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleTextWriter.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleTextWriter.cs
@@ -93,6 +93,6 @@ public override
_ui.WriteToConsole(a, transcribeResult: true);
}
- private ConsoleHostUserInterface _ui;
+ private readonly ConsoleHostUserInterface _ui;
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs
index bdba911e298..e496c3d36d3 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs
@@ -150,7 +150,7 @@ private void PipelineStateChangedHandler(object sender, PipelineStateEventArgs e
}
}
- private System.Threading.ManualResetEvent _eventHandle = new System.Threading.ManualResetEvent(false);
+ private readonly System.Threading.ManualResetEvent _eventHandle = new System.Threading.ManualResetEvent(false);
}
internal void ExecuteCommandAsync(string command, out Exception exceptionThrown, ExecutionOptions options)
@@ -731,14 +731,14 @@ internal static void CancelCurrentExecutor()
// to currentExecutor is guarded by staticStateLock, and static initializers are run by the CLR at program init time.
private static Executor s_currentExecutor;
- private static object s_staticStateLock = new object();
+ private static readonly object s_staticStateLock = new object();
- private ConsoleHost _parent;
+ private readonly ConsoleHost _parent;
private Pipeline _pipeline;
private bool _cancelled;
internal bool useNestedPipelines;
- private object _instanceStateLock = new object();
- private bool _isPromptFunctionExecutor;
+ private readonly object _instanceStateLock = new object();
+ private readonly bool _isPromptFunctionExecutor;
}
} // namespace
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs
index 0d4638cdb6f..b049aede0f0 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs
@@ -404,8 +404,8 @@ internal override
int
IndexWhereFound = -1;
- private int _idToFind = -1;
- private Int64 _sourceIdToFind;
+ private readonly int _idToFind = -1;
+ private readonly Int64 _sourceIdToFind;
}
///
@@ -686,9 +686,9 @@ internal override
return true;
}
- private PSHostRawUserInterface _rawUi;
- private int _maxHeight;
- private int _maxWidth;
+ private readonly PSHostRawUserInterface _rawUi;
+ private readonly int _maxHeight;
+ private readonly int _maxWidth;
internal int Tally;
}
@@ -1017,7 +1017,7 @@ internal static
#endregion
- private ArrayList _topLevelNodes = new ArrayList();
+ private readonly ArrayList _topLevelNodes = new ArrayList();
private int _nodeCount;
private const int maxNodeCount = 128;
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs
index c2a13132e41..8c6aa2e4dcb 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs
@@ -240,8 +240,8 @@ class ProgressPane
private Size _bufSize;
private BufferCell[,] _savedRegion;
private BufferCell[,] _progressRegion;
- private PSHostRawUserInterface _rawui;
- private ConsoleHostUserInterface _ui;
+ private readonly PSHostRawUserInterface _rawui;
+ private readonly ConsoleHostUserInterface _ui;
}
} // namespace
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Serialization.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Serialization.cs
index 696e47313d5..7f4f271a7be 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Serialization.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Serialization.cs
@@ -141,7 +141,7 @@ class WrappedSerializer : Serialization
}
internal TextWriter textWriter;
- private XmlWriter _xmlWriter;
+ private readonly XmlWriter _xmlWriter;
private Serializer _xmlSerializer;
private bool _firstCall = true;
}
@@ -271,8 +271,8 @@ class WrappedDeserializer : Serialization
}
internal TextReader textReader;
- private XmlReader _xmlReader;
- private Deserializer _xmlDeserializer;
+ private readonly XmlReader _xmlReader;
+ private readonly Deserializer _xmlDeserializer;
private string _firstLine;
private bool _atEnd;
}
diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs
index e01249c9bc5..f95ee6002d3 100644
--- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs
+++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs
@@ -11,19 +11,19 @@ namespace System.Diagnostics.Eventing
public struct EventDescriptor
{
[FieldOffset(0)]
- private ushort _id;
+ private readonly ushort _id;
[FieldOffset(2)]
- private byte _version;
+ private readonly byte _version;
[FieldOffset(3)]
- private byte _channel;
+ private readonly byte _channel;
[FieldOffset(4)]
- private byte _level;
+ private readonly byte _level;
[FieldOffset(5)]
- private byte _opcode;
+ private readonly byte _opcode;
[FieldOffset(6)]
- private ushort _task;
+ private readonly ushort _task;
[FieldOffset(8)]
- private long _keywords;
+ private readonly long _keywords;
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "opcode", Justification = "matell: Shipped public in 3.5, breaking change to fix now.")]
public EventDescriptor(
diff --git a/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs b/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs
index 83e99298979..aed66caeb84 100644
--- a/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs
+++ b/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs
@@ -273,11 +273,11 @@ private void SetCodeColor(bool isDarkTheme)
public class VT100EscapeSequences
{
private const char Esc = (char)0x1B;
- private string endSequence = Esc + "[0m";
+ private readonly string endSequence = Esc + "[0m";
// For code blocks, [500@ make sure that the whole line has background color.
private const string LongBackgroundCodeBlock = "[500@";
- private PSMarkdownOptionInfo options;
+ private readonly PSMarkdownOptionInfo options;
///
/// Initializes a new instance of the class.
diff --git a/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs b/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs
index 5d094413904..895a551e057 100644
--- a/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs
+++ b/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs
@@ -60,7 +60,7 @@ public string[] Path
//
// name of this command
//
- private string commandName;
+ private readonly string commandName;
///
/// Initializes a new instance of the CatalogCommandsBase class,
diff --git a/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs b/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs
index 28163845d22..7dc5235edd9 100644
--- a/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs
+++ b/src/Microsoft.PowerShell.Security/security/CertificateCommands.cs
@@ -80,7 +80,7 @@ public string[] LiteralPath
//
// list of files that were not found
//
- private List _filesNotFound = new List();
+ private readonly List _filesNotFound = new List();
///
/// Initializes a new instance of the GetPfxCertificateCommand
diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
index 7bdb8286598..7902dd6a5d1 100644
--- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
+++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
@@ -65,12 +65,12 @@ public struct DnsNameRepresentation
///
/// Punycode version of DNS name.
///
- private string _punycodeName;
+ private readonly string _punycodeName;
///
/// Unicode version of DNS name.
///
- private string _unicodeName;
+ private readonly string _unicodeName;
///
/// Ambiguous constructor of a DnsNameRepresentation.
@@ -451,8 +451,8 @@ public bool Valid
}
private bool _archivedCerts = false;
- private X509StoreLocation _storeLocation = null;
- private string _storeName = null;
+ private readonly X509StoreLocation _storeLocation = null;
+ private readonly string _storeName = null;
private CertificateStoreHandle _storeHandle = null;
private bool _valid = false;
private bool _open = false;
@@ -521,7 +521,7 @@ public sealed class CertificateProvider : NavigationCmdletProvider, ICmdletProvi
/// -- storeLocations
/// -- pathCache.
///
- private static object s_staticLock = new object();
+ private static readonly object s_staticLock = new object();
///
/// List of store locations. They do not change once initialized.
@@ -2893,12 +2893,12 @@ public struct EnhancedKeyUsageRepresentation
///
/// Localized friendly name of EKU.
///
- private string _friendlyName;
+ private readonly string _friendlyName;
///
/// OID of EKU.
///
- private string _oid;
+ private readonly string _oid;
///
/// Constructor of an EnhancedKeyUsageRepresentation.
@@ -3131,7 +3131,7 @@ private static string[] GetPathElements(string path)
public sealed class EnhancedKeyUsageProperty
{
- private List _ekuList = new List();
+ private readonly List _ekuList = new List();
///
/// Get property of EKUList.
@@ -3175,8 +3175,8 @@ public EnhancedKeyUsageProperty(X509Certificate2 cert)
public sealed class DnsNameProperty
{
- private List _dnsList = new List();
- private System.Globalization.IdnMapping idnMapping = new System.Globalization.IdnMapping();
+ private readonly List _dnsList = new List();
+ private readonly System.Globalization.IdnMapping idnMapping = new System.Globalization.IdnMapping();
private const string dnsNamePrefix = "DNS Name=";
private const string distinguishedNamePrefix = "CN=";
@@ -3381,7 +3381,7 @@ internal static class Crypt32Helpers
/// Lock that guards access to the following static members
/// -- storeNames.
///
- private static object s_staticLock = new object();
+ private static readonly object s_staticLock = new object();
internal static List storeNames = new List();
diff --git a/src/Microsoft.PowerShell.Security/security/CmsCommands.cs b/src/Microsoft.PowerShell.Security/security/CmsCommands.cs
index 4c90c02e941..c879ac74a05 100644
--- a/src/Microsoft.PowerShell.Security/security/CmsCommands.cs
+++ b/src/Microsoft.PowerShell.Security/security/CmsCommands.cs
@@ -43,7 +43,7 @@ public PSObject Content
set;
}
- private PSDataCollection _inputObjects = new PSDataCollection();
+ private readonly PSDataCollection _inputObjects = new PSDataCollection();
///
/// Gets or sets the content of the CMS Message by path.
@@ -206,7 +206,7 @@ public string Content
set;
}
- private StringBuilder _contentBuffer = new StringBuilder();
+ private readonly StringBuilder _contentBuffer = new StringBuilder();
///
/// Gets or sets the CMS Message by path.
@@ -351,7 +351,7 @@ public string Content
set;
}
- private StringBuilder _contentBuffer = new StringBuilder();
+ private readonly StringBuilder _contentBuffer = new StringBuilder();
///
/// Gets or sets the Windows Event Log Message with contents to be decrypted.
diff --git a/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs b/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs
index 74dee890cdf..5f7c819fc5e 100644
--- a/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs
+++ b/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs
@@ -35,7 +35,7 @@ protected SecureString SecureStringData
//
// name of this command
//
- private string _commandName;
+ private readonly string _commandName;
///
/// Initializes a new instance of the SecureStringCommandBase
diff --git a/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs b/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs
index ae9004f8dcf..fa4c3dd2c13 100644
--- a/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs
+++ b/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs
@@ -124,7 +124,7 @@ public byte[] Content
//
// name of this command
//
- private string _commandName;
+ private readonly string _commandName;
///
/// Initializes a new instance of the SignatureCommandsBase class,
diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs
index 414b70c8403..88a295ac4e0 100644
--- a/src/Microsoft.WSMan.Management/ConfigProvider.cs
+++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs
@@ -43,12 +43,12 @@ public sealed partial class WSManConfigProvider : NavigationCmdletProvider, ICmd
///
/// Object contains the cache of the enumerate results for the cmdlet to execute.
///
- Dictionary enumerateMapping = new Dictionary();
+ readonly Dictionary