Fix IDE0044: MakeFieldReadonly part 13 (#13968)

https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0044
This commit is contained in:
xtqqczze
2020-11-05 08:29:50 +05:00
committed by GitHub
parent 24facfb03d
commit 4653e9e335
30 changed files with 77 additions and 78 deletions
@@ -151,8 +151,8 @@ namespace System.Management.Automation
#endregion Properties
#region Private
private string _errorId = "CommandNotFoundException";
private ErrorCategory _errorCategory = ErrorCategory.ObjectNotFound;
private readonly string _errorId = "CommandNotFoundException";
private readonly ErrorCategory _errorCategory = ErrorCategory.ObjectNotFound;
private static string BuildMessage(
string commandName,
@@ -413,7 +413,7 @@ namespace System.Management.Automation
get { return _commandName; }
}
private string _commandName = string.Empty;
private readonly string _commandName = string.Empty;
/// <summary>
/// Gets the PSVersion that the script requires.
@@ -423,7 +423,7 @@ namespace System.Management.Automation
get { return _requiresPSVersion; }
}
private Version _requiresPSVersion;
private readonly Version _requiresPSVersion;
/// <summary>
/// Gets the missing snap-ins that the script requires.
@@ -433,7 +433,7 @@ namespace System.Management.Automation
get { return _missingPSSnapIns; }
}
private ReadOnlyCollection<string> _missingPSSnapIns = new ReadOnlyCollection<string>(Array.Empty<string>());
private readonly ReadOnlyCollection<string> _missingPSSnapIns = new ReadOnlyCollection<string>(Array.Empty<string>());
/// <summary>
/// Gets or sets the ID of the shell.
@@ -443,7 +443,7 @@ namespace System.Management.Automation
get { return _requiresShellId; }
}
private string _requiresShellId;
private readonly string _requiresShellId;
/// <summary>
/// Gets or sets the path to the incompatible shell.
@@ -453,7 +453,7 @@ namespace System.Management.Automation
get { return _requiresShellPath; }
}
private string _requiresShellPath;
private readonly string _requiresShellPath;
#endregion Properties
@@ -278,7 +278,7 @@ namespace System.Management.Automation.Internal
{
#region Private Members
private uint _errorCode;
private readonly uint _errorCode;
#endregion Private Members
@@ -386,7 +386,7 @@ namespace System.Management.Automation.Internal
// bool indicating if session key was generated before
private bool _sessionKeyGenerated = false;
private static object s_syncObject = new object();
private static readonly object s_syncObject = new object();
#endregion Private Members
@@ -274,7 +274,7 @@ namespace System.Management.Automation
}
[NonSerialized]
private ProviderInvocationException _providerInvocationException;
private readonly ProviderInvocationException _providerInvocationException;
/// <summary>
/// This is the ProviderInfo associated with the provider which
@@ -123,7 +123,7 @@ namespace System.Management.Automation.Runspaces
internal class DiscardingPipelineWriter : PipelineWriter
{
private ManualResetEvent _waitHandle = new ManualResetEvent(true);
private readonly ManualResetEvent _waitHandle = new ManualResetEvent(true);
public override WaitHandle WaitHandle
{
@@ -151,7 +151,7 @@ namespace System.Management.Automation
get { return _swallowException; }
}
private bool _swallowException = false;
private readonly bool _swallowException = false;
}
/// <summary>
@@ -135,7 +135,7 @@ namespace System.Management.Automation
}
private ErrorRecord _errorRecord;
private string _errorId = "Argument";
private readonly string _errorId = "Argument";
/// <summary>
/// See <see cref="System.Exception.Message"/>
@@ -150,7 +150,7 @@ namespace System.Management.Automation
get { return string.IsNullOrEmpty(_message) ? base.Message : _message; }
}
private string _message;
private readonly string _message;
}
}
@@ -133,7 +133,7 @@ namespace System.Management.Automation
}
private ErrorRecord _errorRecord;
private string _errorId = "ArgumentNull";
private readonly string _errorId = "ArgumentNull";
/// <summary>
/// See <see cref="System.Exception.Message"/>
@@ -148,7 +148,7 @@ namespace System.Management.Automation
get { return string.IsNullOrEmpty(_message) ? base.Message : _message; }
}
private string _message;
private readonly string _message;
}
}
@@ -131,7 +131,7 @@ namespace System.Management.Automation
}
private ErrorRecord _errorRecord;
private string _errorId = "ArgumentOutOfRange";
private readonly string _errorId = "ArgumentOutOfRange";
}
}
@@ -136,8 +136,8 @@ namespace System.Management.Automation
_errorId = errorId;
}
private ErrorCategory _errorCategory = ErrorCategory.InvalidOperation;
private object _target = null;
private readonly ErrorCategory _errorCategory = ErrorCategory.InvalidOperation;
private readonly object _target = null;
}
}
@@ -112,7 +112,7 @@ namespace System.Management.Automation
}
private ErrorRecord _errorRecord;
private string _errorId = "NotImplemented";
private readonly string _errorId = "NotImplemented";
}
}
@@ -112,7 +112,7 @@ namespace System.Management.Automation
}
private ErrorRecord _errorRecord;
private string _errorId = "NotSupported";
private readonly string _errorId = "NotSupported";
}
}
@@ -118,7 +118,7 @@ namespace System.Management.Automation
}
private ErrorRecord _errorRecord;
private string _errorId = "ObjectDisposed";
private readonly string _errorId = "ObjectDisposed";
}
}
@@ -49,7 +49,7 @@ namespace System.Management.Automation
/// <summary>
/// Lock object for the GetTracer method.
/// </summary>
private static object s_getTracerLock = new object();
private static readonly object s_getTracerLock = new object();
/// <summary>
/// A helper to get an instance of the PSTraceSource class.
@@ -201,7 +201,7 @@ namespace System.Management.Automation.Internal
/// we are protected from outside code interfering in our
/// critical section. Thanks to Wintellect for the hint.
/// </remarks>
private object _monitorObject = new object();
private readonly object _monitorObject = new object();
#endregion Private fields
@@ -488,7 +488,7 @@ namespace System.Management.Automation.Internal
{
#region Private Data
private PSDataCollectionEnumerator<DataStoreType> _enumerator;
private readonly PSDataCollectionEnumerator<DataStoreType> _enumerator;
#endregion
@@ -647,7 +647,7 @@ namespace System.Management.Automation.Internal
{
#region Private Data
private PSDataCollection<DataStoreType> _datastore;
private readonly PSDataCollection<DataStoreType> _datastore;
#endregion Private Data
@@ -401,7 +401,7 @@ namespace System.Management.Automation.Internal
// PERF-2003/08/22-JonN We should probably use Queue instead
// PERF-2004/06/30-JonN Probably more efficient to use type
// Collection<object> as the underlying store
private List<object> _objects;
private readonly List<object> _objects;
/// <summary>
/// Is the stream open or closed for writing?
@@ -420,7 +420,7 @@ namespace System.Management.Automation.Internal
/// the stream is closed for reading. Instead, use WaitAny on
/// this handle and also _readClosedHandle.
/// </remarks>
private AutoResetEvent _readHandle;
private readonly AutoResetEvent _readHandle;
/// <summary>
/// Handle returned to callers for blocking on data ready.
@@ -431,7 +431,7 @@ namespace System.Management.Automation.Internal
/// When this handle is set, the stream is closed for reading,
/// so all blocked readers should be released.
/// </summary>
private ManualResetEvent _readClosedHandle;
private readonly ManualResetEvent _readClosedHandle;
/// <summary>
/// Write handle - signaled with the number of objects in the
@@ -446,7 +446,7 @@ namespace System.Management.Automation.Internal
/// the stream is closed for writing. Instead, use WaitAny on
/// this handle and also _writeClosedHandle.
/// </remarks>
private AutoResetEvent _writeHandle;
private readonly AutoResetEvent _writeHandle;
/// <summary>
/// Handle returned to callers for blocking until buffer space
@@ -458,7 +458,7 @@ namespace System.Management.Automation.Internal
/// When this handle is set, the stream is closed for writing,
/// so all blocked readers should be released.
/// </summary>
private ManualResetEvent _writeClosedHandle;
private readonly ManualResetEvent _writeClosedHandle;
#endregion Synchronization handles
/// <summary>
@@ -493,7 +493,7 @@ namespace System.Management.Automation.Internal
/// Note that this is not permitted to be more than Int32.MaxValue,
/// since the underlying list has this limitation.
/// </summary>
private int _capacity = Int32.MaxValue;
private readonly int _capacity = Int32.MaxValue;
/// <summary>
/// This object is used to acquire an exclusive lock on the stream.
@@ -503,7 +503,7 @@ namespace System.Management.Automation.Internal
/// we are protected from outside code interfering in our
/// critical section. Thanks to Wintellect for the hint.
/// </remarks>
private object _monitorObject = new object();
private readonly object _monitorObject = new object();
/// <summary>
/// Indicates if this stream has already been disposed.
@@ -1551,7 +1551,7 @@ namespace System.Management.Automation.Internal
{
#region Private Fields
private PSDataCollection<T> _objects;
private readonly PSDataCollection<T> _objects;
private Guid _psInstanceId;
private bool _isOpen;
private PipelineWriter _writer;
@@ -1559,7 +1559,7 @@ namespace System.Management.Automation.Internal
private PipelineReader<PSObject> _psobjectReader;
private PipelineReader<object> _objectReaderForPipeline;
private PipelineReader<PSObject> _psobjectReaderForPipeline;
private object _syncObject = new object();
private readonly object _syncObject = new object();
private bool _disposed = false;
#endregion
@@ -199,7 +199,7 @@ namespace System.Management.Automation.Internal
/// The underlying stream.
/// </summary>
/// <remarks>Can never be null</remarks>
private ObjectStreamBase _stream;
private readonly ObjectStreamBase _stream;
#endregion Private Fields
}
@@ -401,7 +401,7 @@ namespace System.Management.Automation
}
}
private string _parameterName = string.Empty;
private readonly string _parameterName = string.Empty;
/// <summary>
/// Gets the type the parameter is expecting.
@@ -414,7 +414,7 @@ namespace System.Management.Automation
}
}
private Type _parameterType;
private readonly Type _parameterType;
/// <summary>
/// Gets the Type that was specified as the parameter value.
@@ -427,7 +427,7 @@ namespace System.Management.Automation
}
}
private Type _typeSpecified;
private readonly Type _typeSpecified;
/// <summary>
/// Gets the errorId of this ParameterBindingException.
@@ -440,7 +440,7 @@ namespace System.Management.Automation
}
}
private string _errorId;
private readonly string _errorId;
/// <summary>
/// Gets the line in the script at which the error occurred.
@@ -453,7 +453,7 @@ namespace System.Management.Automation
}
}
private Int64 _line = Int64.MinValue;
private readonly Int64 _line = Int64.MinValue;
/// <summary>
/// Gets the offset on the line in the script at which the error occurred.
@@ -466,7 +466,7 @@ namespace System.Management.Automation
}
}
private Int64 _offset = Int64.MinValue;
private readonly Int64 _offset = Int64.MinValue;
/// <summary>
/// Gets the invocation information about the command.
@@ -479,14 +479,14 @@ namespace System.Management.Automation
}
}
private InvocationInfo _invocationInfo;
private readonly InvocationInfo _invocationInfo;
#endregion Properties
#region private
private string _resourceString;
private object[] _args = Array.Empty<object>();
private string _commandName;
private readonly string _resourceString;
private readonly object[] _args = Array.Empty<object>();
private readonly string _commandName;
private string BuildMessage()
{
@@ -16,7 +16,7 @@ namespace System.Management.Automation
{
private const string errorIdString = "Parse";
private ParseError[] _errors;
private readonly ParseError[] _errors;
/// <summary>
/// The list of parser errors.
@@ -568,7 +568,7 @@ namespace System.Management.Automation
// CRC-32C polynomial representations
private const uint polynomial = 0x1EDC6F41;
private static uint[] table;
private static readonly uint[] table;
static CRC32Hash()
{
@@ -16,13 +16,13 @@ namespace System.Management.Automation
/// to the default resource assembly. The value is another dictionary that is keyed based on the base
/// name for the resource that is being retrieved. The value for this dictionary is the ResourceManager.
/// </summary>
private static Dictionary<string, Dictionary<string, ResourceManager>> s_resourceManagerCache =
private static readonly Dictionary<string, Dictionary<string, ResourceManager>> s_resourceManagerCache =
new Dictionary<string, Dictionary<string, ResourceManager>>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Used to synchronize access to the ResourceManagerCache.
/// </summary>
private static object s_syncRoot = new object();
private static readonly object s_syncRoot = new object();
/// <summary>
/// Gets the ResourceManager from the cache or gets an instance of the ResourceManager
@@ -322,7 +322,7 @@ namespace System.Management.Automation
}
[NonSerialized]
private string _message /* = null */;
private readonly string _message /* = null */;
#endregion Private/Internal
}
@@ -520,7 +520,7 @@ namespace System.Management.Automation
get { return _itemName; }
}
private string _itemName = string.Empty;
private readonly string _itemName = string.Empty;
/// <summary>
/// Gets the category of session state object the error occurred on.
@@ -530,12 +530,12 @@ namespace System.Management.Automation
get { return _sessionStateCategory; }
}
private SessionStateCategory _sessionStateCategory = SessionStateCategory.Variable;
private readonly SessionStateCategory _sessionStateCategory = SessionStateCategory.Variable;
#endregion Properties
#region Private
private string _errorId = "SessionStateException";
private ErrorCategory _errorCategory = ErrorCategory.InvalidArgument;
private readonly string _errorId = "SessionStateException";
private readonly ErrorCategory _errorCategory = ErrorCategory.InvalidArgument;
private static string BuildMessage(
string itemName,
@@ -853,7 +853,7 @@ namespace System.Management.Automation
}
}
private ReadOnlyCollection<ProviderInfo> _possibleMatches;
private readonly ReadOnlyCollection<ProviderInfo> _possibleMatches;
#endregion public properties
}
@@ -1436,7 +1436,7 @@ namespace System.Management.Automation
/// </summary>
internal string FullName { get; } = string.Empty;
private string _name;
private readonly string _name;
/// <summary>
/// Creates an instance of the TraceSource on demand.
@@ -1765,7 +1765,7 @@ namespace System.Management.Automation
/// <summary>
/// The trace object that is used for any output.
/// </summary>
private PSTraceSource _tracer;
private readonly PSTraceSource _tracer;
/// <summary>
/// The flag which caused this scope object to be created.
@@ -93,7 +93,7 @@ namespace Microsoft.PowerShell.Telemetry
/// Use a hashset for quick lookups.
/// We send telemetry only a known set of modules.
/// If it's not in the list (initialized in the static constructor), then we report anonymous.
private static HashSet<string> s_knownModules;
private static readonly HashSet<string> s_knownModules;
/// <summary>Gets a value indicating whether telemetry can be sent.</summary>
public static bool CanSendTelemetry { get; private set; }
@@ -1311,8 +1311,8 @@ namespace System.Management.Automation
#endif
}
private static Dictionary<string, bool> s_validVerbs = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private static Dictionary<string, string[]> s_recommendedAlternateVerbs = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<string, bool> s_validVerbs = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<string, string[]> s_recommendedAlternateVerbs = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
internal static bool IsStandard(string verb)
{
@@ -72,7 +72,7 @@ namespace System.Management.Automation
return frameString.ToString();
}
private static object s_throwInsteadOfAssertLock = 1;
private static readonly object s_throwInsteadOfAssertLock = 1;
private static bool s_throwInsteadOfAssert = false;
/// <summary>
@@ -96,9 +96,9 @@ namespace System.Management.Automation.Tracing
/// </summary>
private class CorrelatedCallback
{
private CallbackNoParameter callbackNoParam;
private CallbackWithState callbackWithState;
private AsyncCallback asyncCallback;
private readonly CallbackNoParameter callbackNoParam;
private readonly CallbackWithState callbackWithState;
private readonly AsyncCallback asyncCallback;
/// <summary>
/// ParentActivityId.
@@ -175,7 +175,7 @@ namespace System.Management.Automation.Tracing
/// <summary>
/// It is to be used in System.Timers.Timer scenarios.
/// </summary>
private CallbackWithStateAndArgs callbackWithStateAndArgs;
private readonly CallbackWithStateAndArgs callbackWithStateAndArgs;
/// <summary>
/// EtwCorrelator Constructor.
@@ -252,8 +252,8 @@ namespace System.Management.Automation.Tracing
}
}
private static Dictionary<Guid, EventProvider> providers = new Dictionary<Guid, EventProvider>();
private static object syncLock = new object();
private static readonly Dictionary<Guid, EventProvider> providers = new Dictionary<Guid, EventProvider>();
private static readonly object syncLock = new object();
private static EventDescriptor _WriteTransferEvent = new EventDescriptor(0x1f05, 0x1, 0x11, 0x5, 0x14, 0x0, (long)0x4000000000000000);
@@ -13,9 +13,9 @@ namespace System.Management.Automation.Tracing
internal static class PSEtwLog
{
#if UNIX
private static PSSysLogProvider provider;
private static readonly PSSysLogProvider provider;
#else
private static PSEtwLogProvider provider;
private static readonly PSEtwLogProvider provider;
#endif
/// <summary>
@@ -15,7 +15,7 @@ namespace System.Management.Automation.Tracing
/// </summary>
internal class PSEtwLogProvider : LogProvider
{
private static EventProvider etwProvider;
private static readonly EventProvider etwProvider;
internal static readonly Guid ProviderGuid = new Guid("F90714A8-5509-434A-BF6D-B1624C8A19A2");
private static EventDescriptor _xferEventDescriptor = new EventDescriptor(0x1f05, 0x1, 0x11, 0x5, 0x14, 0x0, (long)0x4000000000000000);
@@ -16,7 +16,7 @@ namespace System.Management.Automation.Tracing
/// </summary>
internal class PSSysLogProvider : LogProvider
{
private static SysLogProvider s_provider;
private static readonly SysLogProvider s_provider;
// by default, do not include channel bits
internal const PSKeyword DefaultKeywords = (PSKeyword) (0x00FFFFFFFFFFFFFF);
@@ -81,11 +81,10 @@ namespace System.Management.Automation.Tracing
{
// Ensure the string pointer is not garbage collected.
static IntPtr _nativeSyslogIdent = IntPtr.Zero;
static NativeMethods.SysLogPriority _facility = NativeMethods.SysLogPriority.Local0;
byte _channelFilter;
ulong _keywordFilter;
byte _levelFilter;
static readonly NativeMethods.SysLogPriority _facility = NativeMethods.SysLogPriority.Local0;
readonly byte _channelFilter;
readonly ulong _keywordFilter;
readonly byte _levelFilter;
/// <summary>
/// Initializes a new instance of this class.
@@ -276,7 +275,7 @@ namespace System.Management.Automation.Tracing
#region logging
// maps a LogLevel to an associated SysLogPriority.
static NativeMethods.SysLogPriority[] _levels =
static readonly NativeMethods.SysLogPriority[] _levels =
{
NativeMethods.SysLogPriority.Info,
NativeMethods.SysLogPriority.Critical,