Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public string CommandName
#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,
Expand Down Expand Up @@ -413,7 +413,7 @@ public string CommandName
get { return _commandName; }
}

private string _commandName = string.Empty;
private readonly string _commandName = string.Empty;

/// <summary>
/// Gets the PSVersion that the script requires.
Expand All @@ -423,7 +423,7 @@ public Version RequiresPSVersion
get { return _requiresPSVersion; }
}

private Version _requiresPSVersion;
private readonly Version _requiresPSVersion;

/// <summary>
/// Gets the missing snap-ins that the script requires.
Expand All @@ -433,7 +433,7 @@ public ReadOnlyCollection<string> MissingPSSnapIns
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.
Expand All @@ -443,7 +443,7 @@ public string RequiresShellId
get { return _requiresShellId; }
}

private string _requiresShellId;
private readonly string _requiresShellId;

/// <summary>
/// Gets or sets the path to the incompatible shell.
Expand All @@ -453,7 +453,7 @@ public string RequiresShellPath
get { return _requiresShellPath; }
}

private string _requiresShellPath;
private readonly string _requiresShellPath;

#endregion Properties

Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/utils/CryptoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ internal class PSCryptoException : Exception
{
#region Private Members

private uint _errorCode;
private readonly uint _errorCode;

#endregion Private Members

Expand Down Expand Up @@ -386,7 +386,7 @@ internal class PSRSACryptoServiceProvider : IDisposable
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public ProviderInvocationException ProviderInvocationException
}

[NonSerialized]
private ProviderInvocationException _providerInvocationException;
private readonly ProviderInvocationException _providerInvocationException;

/// <summary>
/// This is the ProviderInfo associated with the provider which
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/IObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public abstract int MaxCapacity

internal class DiscardingPipelineWriter : PipelineWriter
{
private ManualResetEvent _waitHandle = new ManualResetEvent(true);
private readonly ManualResetEvent _waitHandle = new ManualResetEvent(true);

public override WaitHandle WaitHandle
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal bool SwallowException
get { return _swallowException; }
}

private bool _swallowException = false;
private readonly bool _swallowException = false;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public ErrorRecord ErrorRecord
}

private ErrorRecord _errorRecord;
private string _errorId = "Argument";
private readonly string _errorId = "Argument";

/// <summary>
/// See <see cref="System.Exception.Message"/>
Expand All @@ -150,7 +150,7 @@ public override string Message
get { return string.IsNullOrEmpty(_message) ? base.Message : _message; }
}

private string _message;
private readonly string _message;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public ErrorRecord ErrorRecord
}

private ErrorRecord _errorRecord;
private string _errorId = "ArgumentNull";
private readonly string _errorId = "ArgumentNull";

/// <summary>
/// See <see cref="System.Exception.Message"/>
Expand All @@ -148,7 +148,7 @@ public override string Message
get { return string.IsNullOrEmpty(_message) ? base.Message : _message; }
}

private string _message;
private readonly string _message;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public ErrorRecord ErrorRecord
}

private ErrorRecord _errorRecord;
private string _errorId = "ArgumentOutOfRange";
private readonly string _errorId = "ArgumentOutOfRange";
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ internal void SetErrorId(string errorId)
_errorId = errorId;
}

private ErrorCategory _errorCategory = ErrorCategory.InvalidOperation;
private object _target = null;
private readonly ErrorCategory _errorCategory = ErrorCategory.InvalidOperation;
private readonly object _target = null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ErrorRecord ErrorRecord
}

private ErrorRecord _errorRecord;
private string _errorId = "NotImplemented";
private readonly string _errorId = "NotImplemented";
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ErrorRecord ErrorRecord
}

private ErrorRecord _errorRecord;
private string _errorId = "NotSupported";
private readonly string _errorId = "NotSupported";
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public ErrorRecord ErrorRecord
}

private ErrorRecord _errorRecord;
private string _errorId = "ObjectDisposed";
private readonly string _errorId = "ObjectDisposed";
}
}

2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/MshTraceSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public partial class PSTraceSource
/// <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.
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/utils/ObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void OnDataReady(object sender, EventArgs args)
/// 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

Expand Down Expand Up @@ -488,7 +488,7 @@ internal class PSDataCollectionReader<DataStoreType, ReturnType>
{
#region Private Data

private PSDataCollectionEnumerator<DataStoreType> _enumerator;
private readonly PSDataCollectionEnumerator<DataStoreType> _enumerator;

#endregion

Expand Down Expand Up @@ -647,7 +647,7 @@ internal class PSDataCollectionPipelineReader<DataStoreType, ReturnType>
{
#region Private Data

private PSDataCollection<DataStoreType> _datastore;
private readonly PSDataCollection<DataStoreType> _datastore;

#endregion Private Data

Expand Down
18 changes: 9 additions & 9 deletions src/System.Management.Automation/utils/ObjectStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ internal sealed class ObjectStream : ObjectStreamBase, IDisposable
// 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?
Expand All @@ -420,7 +420,7 @@ internal sealed class ObjectStream : ObjectStreamBase, IDisposable
/// 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.
Expand All @@ -431,7 +431,7 @@ internal sealed class ObjectStream : ObjectStreamBase, IDisposable
/// 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
Expand All @@ -446,7 +446,7 @@ internal sealed class ObjectStream : ObjectStreamBase, IDisposable
/// 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
Expand All @@ -458,7 +458,7 @@ internal sealed class ObjectStream : ObjectStreamBase, IDisposable
/// 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>
Expand Down Expand Up @@ -493,7 +493,7 @@ internal sealed class ObjectStream : ObjectStreamBase, IDisposable
/// 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.
Expand All @@ -503,7 +503,7 @@ internal sealed class ObjectStream : ObjectStreamBase, IDisposable
/// 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.
Expand Down Expand Up @@ -1551,15 +1551,15 @@ internal sealed class PSDataCollectionStream<T> : ObjectStreamBase
{
#region Private Fields

private PSDataCollection<T> _objects;
private readonly PSDataCollection<T> _objects;
private Guid _psInstanceId;
private bool _isOpen;
private PipelineWriter _writer;
private PipelineReader<object> _objectReader;
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
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/ObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void OnWriteReady (object sender, EventArgs args)
/// The underlying stream.
/// </summary>
/// <remarks>Can never be null</remarks>
private ObjectStreamBase _stream;
private readonly ObjectStreamBase _stream;

#endregion Private Fields
}
Expand Down
20 changes: 10 additions & 10 deletions src/System.Management.Automation/utils/ParameterBinderExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public string ParameterName
}
}

private string _parameterName = string.Empty;
private readonly string _parameterName = string.Empty;

/// <summary>
/// Gets the type the parameter is expecting.
Expand All @@ -414,7 +414,7 @@ public Type ParameterType
}
}

private Type _parameterType;
private readonly Type _parameterType;

/// <summary>
/// Gets the Type that was specified as the parameter value.
Expand All @@ -427,7 +427,7 @@ public Type TypeSpecified
}
}

private Type _typeSpecified;
private readonly Type _typeSpecified;

/// <summary>
/// Gets the errorId of this ParameterBindingException.
Expand All @@ -440,7 +440,7 @@ public string ErrorId
}
}

private string _errorId;
private readonly string _errorId;

/// <summary>
/// Gets the line in the script at which the error occurred.
Expand All @@ -453,7 +453,7 @@ public Int64 Line
}
}

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.
Expand All @@ -466,7 +466,7 @@ public Int64 Offset
}
}

private Int64 _offset = Int64.MinValue;
private readonly Int64 _offset = Int64.MinValue;

/// <summary>
/// Gets the invocation information about the command.
Expand All @@ -479,14 +479,14 @@ public InvocationInfo CommandInvocation
}
}

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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/ParserException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ParseException : RuntimeException
{
private const string errorIdString = "Parse";

private ParseError[] _errors;
private readonly ParseError[] _errors;

/// <summary>
/// The list of parser errors.
Expand Down
Loading