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
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/ApplicationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal ApplicationInfo(string name, string path, ExecutionContext context) : b
_context = context;
}

private ExecutionContext _context;
private readonly ExecutionContext _context;
#endregion ctor

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal ArgumentTypeConverterAttribute(params Type[] types)
_convertTypes = types;
}

private Type[] _convertTypes;
private readonly Type[] _convertTypes;

internal Type TargetType
{
Expand Down
18 changes: 9 additions & 9 deletions src/System.Management.Automation/engine/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,27 +938,27 @@ public sealed class ValidateRangeAttribute : ValidateEnumeratedArgumentsAttribut
/// </summary>
public object MinRange { get; }

private IComparable _minComparable;
private readonly IComparable _minComparable;

/// <summary>
/// Gets the attribute's maximum range.
/// </summary>
public object MaxRange { get; }

private IComparable _maxComparable;
private readonly IComparable _maxComparable;

/// <summary>
/// The range values and the value to validate will all be converted to the promoted type.
/// If minRange and maxRange are the same type,
/// </summary>
private Type _promotedType;
private readonly Type _promotedType;

/// <summary>
/// Gets the name of the predefined range.
/// </summary>
internal ValidateRangeKind? RangeKind { get => _rangeKind; }

private ValidateRangeKind? _rangeKind;
private readonly ValidateRangeKind? _rangeKind;

/// <summary>
/// Validates that each parameter argument falls in the range specified by <see cref="MinRange"/>
Expand Down Expand Up @@ -1532,7 +1532,7 @@ public abstract class CachedValidValuesGeneratorBase : IValidateSetValuesGenerat
{
// Cached valid values.
private string[] _validValues;
private int _validValuesCacheExpiration;
private readonly int _validValuesCacheExpiration;

/// <summary>
/// Initializes a new instance of the <see cref="CachedValidValuesGeneratorBase"/> class.
Expand Down Expand Up @@ -1591,11 +1591,11 @@ public sealed class ValidateSetAttribute : ValidateEnumeratedArgumentsAttribute
{
// We can use either static '_validValues' or dynamic valid values list generated by instance
// of 'validValuesGenerator'.
private string[] _validValues;
private IValidateSetValuesGenerator validValuesGenerator = null;
private readonly string[] _validValues;
private readonly IValidateSetValuesGenerator validValuesGenerator = null;

// The valid values generator cache works across 'ValidateSetAttribute' instances.
private static ConcurrentDictionary<Type, IValidateSetValuesGenerator> s_ValidValuesGeneratorCache =
private static readonly ConcurrentDictionary<Type, IValidateSetValuesGenerator> s_ValidValuesGeneratorCache =
new ConcurrentDictionary<Type, IValidateSetValuesGenerator>();

/// <summary>
Expand Down Expand Up @@ -1821,7 +1821,7 @@ public AllowEmptyCollectionAttribute() { }
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ValidateDriveAttribute : ValidateArgumentsAttribute
{
private string[] _validRootDrives;
private readonly string[] _validRootDrives;

/// <summary>
/// Gets the values in the set.
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/COM/ComMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ internal ComMethodInformation(bool hasvarargs, bool hasoptional, ParameterInform
/// </summary>
internal class ComMethod
{
private Collection<int> _methods = new Collection<int>();
private COM.ITypeInfo _typeInfo;
private readonly Collection<int> _methods = new Collection<int>();
private readonly COM.ITypeInfo _typeInfo;

/// <summary>
/// Initializes new instance of ComMethod class.
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/COM/ComProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class ComProperty
private int _setterIndex;
private int _setterByRefIndex;
private int _getterIndex;
private COM.ITypeInfo _typeInfo;
private readonly COM.ITypeInfo _typeInfo;

/// <summary>
/// Initializes a new instance of ComProperty.
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/COM/ComTypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ internal class ComTypeInfo
/// <summary>
/// Member variables.
/// </summary>
private Dictionary<string, ComProperty> _properties = null;
private Dictionary<string, ComMethod> _methods = null;
private COM.ITypeInfo _typeinfo = null;
private readonly Dictionary<string, ComProperty> _properties = null;
private readonly Dictionary<string, ComMethod> _methods = null;
private readonly COM.ITypeInfo _typeinfo = null;
private Guid _guid = Guid.Empty;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ internal bool HasChild(

#region private data

private Cmdlet _cmdlet;
private SessionStateInternal _sessionState;
private readonly Cmdlet _cmdlet;
private readonly SessionStateInternal _sessionState;

#endregion private data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal ProviderIntrinsics(SessionStateInternal sessionState)

#region private data

private InternalCommand _cmdlet;
private readonly InternalCommand _cmdlet;

#endregion private data
}
Expand Down
8 changes: 4 additions & 4 deletions src/System.Management.Automation/engine/CmdletInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public string Verb
}
}

private string _verb = string.Empty;
private readonly string _verb = string.Empty;

/// <summary>
/// Gets the noun of the cmdlet.
Expand All @@ -162,7 +162,7 @@ public string Noun
}
}

private string _noun = string.Empty;
private readonly string _noun = string.Empty;

internal static bool SplitCmdletName(string name, out string verb, out string noun)
{
Expand Down Expand Up @@ -224,7 +224,7 @@ public PSSnapInInfo PSSnapIn
}
}

private PSSnapInInfo _PSSnapin;
private readonly PSSnapInInfo _PSSnapin;

/// <summary>
/// Gets the name of the PSSnapin the cmdlet is implemented in.
Expand Down Expand Up @@ -279,7 +279,7 @@ public Type ImplementingType
}
}

private Type _implementingType = null;
private readonly Type _implementingType = null;

/// <summary>
/// Gets the synopsis of the cmdlet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed class ComInvokeBinder
private readonly bool[] _isByRef;
private readonly Expression _instance;

private BindingRestrictions _restrictions;
private readonly BindingRestrictions _restrictions;

private VarEnumSelector _varEnumSelector;
private string[] _keywordArgNames;
Expand Down
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/ComInterop/ExcepInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace System.Management.Automation.ComInterop
[StructLayout(LayoutKind.Sequential)]
internal struct ExcepInfo
{
private short _wCode;
private readonly short _wCode;
private short _wReserved;
private IntPtr _bstrSource;
private IntPtr _bstrDescription;
private IntPtr _bstrHelpFile;
private int _dwHelpContext;
private IntPtr _pvReserved;
private IntPtr _pfnDeferredFillIn;
private int _scode;
private readonly int _dwHelpContext;
private readonly IntPtr _pvReserved;
private readonly IntPtr _pfnDeferredFillIn;
private readonly int _scode;

#if DEBUG
static ExcepInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ internal static List<CompletionResult> CompleteModuleName(CompletionContext cont
#endregion Module Names

#region Command Parameters
private static string[] s_parameterNamesOfImportDSCResource = { "Name", "ModuleName", "ModuleVersion" };
private static readonly string[] s_parameterNamesOfImportDSCResource = { "Name", "ModuleName", "ModuleVersion" };

internal static List<CompletionResult> CompleteCommandParameter(CompletionContext context)
{
Expand Down Expand Up @@ -2570,7 +2570,7 @@ private static void NativeCompletionCimCommands(
}
}

private static ConcurrentDictionary<string, IEnumerable<string>> s_cimNamespaceAndClassNameToAssociationResultClassNames =
private static readonly ConcurrentDictionary<string, IEnumerable<string>> s_cimNamespaceAndClassNameToAssociationResultClassNames =
new ConcurrentDictionary<string, IEnumerable<string>>(StringComparer.OrdinalIgnoreCase);

private static IEnumerable<string> NativeCompletionCimAssociationResultClassName_GetResultClassNames(
Expand Down Expand Up @@ -2705,7 +2705,7 @@ private static void NativeCompletionCimMethodName(
result.AddRange(localResults.OrderBy(x => x.ListItemText, StringComparer.OrdinalIgnoreCase));
}

private static ConcurrentDictionary<string, IEnumerable<string>> s_cimNamespaceToClassNames =
private static readonly ConcurrentDictionary<string, IEnumerable<string>> s_cimNamespaceToClassNames =
new ConcurrentDictionary<string, IEnumerable<string>>(StringComparer.OrdinalIgnoreCase);

private static IEnumerable<string> NativeCompletionCimClassName_GetClassNames(string targetNamespace)
Expand Down Expand Up @@ -4507,7 +4507,7 @@ private struct SHARE_INFO_1
private const int STYPE_DISKTREE = 0;
private const int STYPE_MASK = 0x000000FF;

private static System.IO.EnumerationOptions _enumerationOptions = new System.IO.EnumerationOptions
private static readonly System.IO.EnumerationOptions _enumerationOptions = new System.IO.EnumerationOptions
{
MatchCasing = MatchCasing.CaseInsensitive,
AttributesToSkip = 0 // Default is to skip Hidden and System files, so we clear this to retain existing behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ public class CompletionResult
/// <summary>
/// Text to be used as the auto completion result.
/// </summary>
private string _completionText;
private readonly string _completionText;

/// <summary>
/// Text to be displayed in a list.
/// </summary>
private string _listItemText;
private readonly string _listItemText;

/// <summary>
/// The text for the tooltip with details to be displayed about the object.
/// </summary>
private string _toolTip;
private readonly string _toolTip;

/// <summary>
/// Type of completion result.
/// </summary>
private CompletionResultType _resultType;
private readonly CompletionResultType _resultType;

/// <summary>
/// Private member for null instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected override void EndProcessing()
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ArgumentCompletionsAttribute : Attribute
{
private string[] _completions;
private readonly string[] _completions;

/// <summary>
/// Initializes a new instance of the ArgumentCompletionsAttribute class.
Expand Down
12 changes: 6 additions & 6 deletions src/System.Management.Automation/engine/CommandDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal CommandLookupEventArgs(string commandName, CommandOrigin commandOrigin,
_context = context;
}

private ExecutionContext _context;
private readonly ExecutionContext _context;

/// <summary>
/// The name of the command we're looking for.
Expand Down Expand Up @@ -1281,10 +1281,10 @@ internal void UnregisterLookupCommandInfoAction(string currentAction, string com
currentActionSet.Remove(command);
}

private HashSet<string> _activePreLookup = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private HashSet<string> _activeModuleSearch = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private HashSet<string> _activeCommandNotFound = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private HashSet<string> _activePostCommand = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> _activePreLookup = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> _activeModuleSearch = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> _activeCommandNotFound = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> _activePostCommand = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Gets the resolved paths contained in the PATH environment
Expand Down Expand Up @@ -1428,7 +1428,7 @@ private static void InitPathExtCache(string pathExt)

#region private members

private static object s_lockObject = new object();
private static readonly object s_lockObject = new object();
private static string s_pathExtCacheKey;
private static string[] s_cachedPathExtCollection;
private static string[] s_cachedPathExtCollectionWithPs1;
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/CommandMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ private static Collection<CommandMetadata> GetRestrictedJobCommands()
/// The command metadata cache. This is separate from the parameterMetadata cache
/// because it is specific to cmdlets.
/// </summary>
private static System.Collections.Concurrent.ConcurrentDictionary<string, CommandMetadata> s_commandMetadataCache =
private static readonly System.Collections.Concurrent.ConcurrentDictionary<string, CommandMetadata> s_commandMetadataCache =
new System.Collections.Concurrent.ConcurrentDictionary<string, CommandMetadata>(StringComparer.OrdinalIgnoreCase);

#endregion
Expand Down
14 changes: 7 additions & 7 deletions src/System.Management.Automation/engine/CommandPathSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ private void GetNewDirectoryResults(string pattern, string directory)
/// The directory paths in which to look for commands.
/// This is derived from the PATH environment variable.
/// </summary>
private LookupPathCollection _lookupPaths;
private readonly LookupPathCollection _lookupPaths;

/// <summary>
/// The enumerator for the lookup paths.
Expand All @@ -552,7 +552,7 @@ private void GetNewDirectoryResults(string pattern, string directory)
/// <summary>
/// The command name to search for.
/// </summary>
private IEnumerable<string> _patterns;
private readonly IEnumerable<string> _patterns;

/// <summary>
/// The enumerator for the patterns.
Expand All @@ -562,7 +562,7 @@ private void GetNewDirectoryResults(string pattern, string directory)
/// <summary>
/// A reference to the execution context for this runspace.
/// </summary>
private ExecutionContext _context;
private readonly ExecutionContext _context;

/// <summary>
/// When reset is called, this gets set to true. Once MoveNext
Expand All @@ -573,12 +573,12 @@ private void GetNewDirectoryResults(string pattern, string directory)
/// <summary>
/// If not null, called with the enumerated files for further processing.
/// </summary>
private Func<string[], IEnumerable<string>?> _postProcessEnumeratedFiles;
private readonly Func<string[], IEnumerable<string>?> _postProcessEnumeratedFiles;

private string[] _orderedPathExt;
private Collection<string>? _acceptableCommandNames;
private readonly string[] _orderedPathExt;
private readonly Collection<string>? _acceptableCommandNames;

private bool _useFuzzyMatch = false;
private readonly bool _useFuzzyMatch = false;

#endregion private members
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public string PipelineVariable

#endregion parameters

private MshCommandRuntime _commandRuntime;
private readonly MshCommandRuntime _commandRuntime;

internal class ValidateVariableName : ValidateArgumentsAttribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ internal object ClearContentDynamicParameters(string path, CmdletProviderContext

#region private data

private Cmdlet _cmdlet;
private SessionStateInternal _sessionState;
private readonly Cmdlet _cmdlet;
private readonly SessionStateInternal _sessionState;

#endregion private data
}
Expand Down
Loading