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 @@ -21,7 +21,7 @@ namespace Microsoft.PowerShell.Commands
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113280", RemotingCapability = RemotingCapability.None)]
public class AddMemberCommand : PSCmdlet
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private void ProcessPaths(List<string> resolvedPaths)
break;

case ".DLL":
loadAssembly = true;
_loadAssembly = true;
break;

// Throw an error if it is an unrecognized extension
Expand Down Expand Up @@ -280,7 +280,7 @@ private void ProcessPaths(List<string> resolvedPaths)
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public string[] AssemblyName { get; set; }

private bool loadAssembly = false;
private bool _loadAssembly = false;

/// <summary>
/// The language used to compile the source code.
Expand All @@ -301,15 +301,15 @@ private void ProcessPaths(List<string> resolvedPaths)
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public string[] ReferencedAssemblies
{
get { return referencedAssemblies; }
get { return _referencedAssemblies; }

set
{
if (value != null) { referencedAssemblies = value; }
if (value != null) { _referencedAssemblies = value; }
}
}

private string[] referencedAssemblies = Array.Empty<string>();
private string[] _referencedAssemblies = Array.Empty<string>();

/// <summary>
/// The path to the output assembly.
Expand Down Expand Up @@ -587,7 +587,7 @@ protected override void EndProcessing()
}


if (loadAssembly)
if (_loadAssembly)
{
// File extension is ".DLL" (ParameterSetName = FromPathParameterSetName or FromLiteralPathParameterSetName).
LoadAssemblies(_paths);
Expand All @@ -608,29 +608,29 @@ protected override void EndProcessing()
// We now ship .Net Core's reference assemblies with PowerShell Core, so that Add-Type can work
// in a predictable way and won't be broken when we move to newer version of .NET Core.
// The reference assemblies are located at '$PSHOME\ref'.
private static string s_netcoreAppRefFolder = PathType.Combine(PathType.GetDirectoryName(typeof(PSObject).Assembly.Location), "ref");
private static string s_frameworkFolder = PathType.GetDirectoryName(typeof(object).Assembly.Location);
private static readonly string s_netcoreAppRefFolder = PathType.Combine(PathType.GetDirectoryName(typeof(PSObject).Assembly.Location), "ref");
private static readonly string s_frameworkFolder = PathType.GetDirectoryName(typeof(object).Assembly.Location);

// These assemblies are always automatically added to ReferencedAssemblies.
private static Lazy<PortableExecutableReference[]> s_autoReferencedAssemblies = new Lazy<PortableExecutableReference[]>(InitAutoIncludedRefAssemblies);
private static readonly Lazy<PortableExecutableReference[]> s_autoReferencedAssemblies = new Lazy<PortableExecutableReference[]>(InitAutoIncludedRefAssemblies);

// A HashSet of assembly names to be ignored if they are specified in '-ReferencedAssemblies'
private static Lazy<HashSet<string>> s_refAssemblyNamesToIgnore = new Lazy<HashSet<string>>(InitRefAssemblyNamesToIgnore);
private static readonly Lazy<HashSet<string>> s_refAssemblyNamesToIgnore = new Lazy<HashSet<string>>(InitRefAssemblyNamesToIgnore);

// These assemblies are used, when ReferencedAssemblies parameter is not specified.
private static Lazy<IEnumerable<PortableExecutableReference>> s_defaultAssemblies = new Lazy<IEnumerable<PortableExecutableReference>>(InitDefaultRefAssemblies);
private static readonly Lazy<IEnumerable<PortableExecutableReference>> s_defaultAssemblies = new Lazy<IEnumerable<PortableExecutableReference>>(InitDefaultRefAssemblies);

private bool InMemory { get { return string.IsNullOrEmpty(_outputAssembly); } }

// These dictionaries prevent reloading already loaded and unchanged code.
// We don't worry about unbounded growing of the cache because in .Net Core 2.0 we can not unload assemblies.
// TODO: review if we will be able to unload assemblies after migrating to .Net Core 2.1.
private static Dictionary<string, int> s_sourceTypesCache = new Dictionary<string, int>();
private static Dictionary<int, Assembly> s_sourceAssemblyCache = new Dictionary<int, Assembly>();
private static readonly Dictionary<string, int> s_sourceTypesCache = new Dictionary<string, int>();
private static readonly Dictionary<int, Assembly> s_sourceAssemblyCache = new Dictionary<int, Assembly>();

private static readonly string s_defaultSdkDirectory = Utils.DefaultPowerShellAppBase;
private const ReportDiagnostic defaultDiagnosticOption = ReportDiagnostic.Error;
private static string[] s_writeInformationTags = new string[] { "PSHOST" };
private static readonly string[] s_writeInformationTags = new string[] { "PSHOST" };
private int _syntaxTreesHash;

private const string FromMemberParameterSetName = "FromMember";
Expand Down Expand Up @@ -1084,7 +1084,7 @@ private void CheckDuplicateTypes(Compilation compilation, out ConcurrentBag<stri
// Visit symbols in all namespaces and collect duplicates.
private class AllNamedTypeSymbolsVisitor : SymbolVisitor
{
private int _hash;
private readonly int _hash;

public readonly ConcurrentBag<string> DuplicateSymbols = new ConcurrentBag<string>();
public readonly ConcurrentBag<string> UniqueSymbols = new ConcurrentBag<string>();
Expand Down Expand Up @@ -1333,6 +1333,5 @@ private static int SyntaxTreeGetHashCode(SyntaxTree st)
}

#endregion SourceCodeProcessing

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public SwitchParameter PassThru

#region Internal
private List<OrderByPropertyEntry> _referenceEntries;
private List<OrderByPropertyEntry> _referenceEntryBacklog
private readonly List<OrderByPropertyEntry> _referenceEntryBacklog
= new List<OrderByPropertyEntry>();
private List<OrderByPropertyEntry> _differenceEntryBacklog
private readonly List<OrderByPropertyEntry> _differenceEntryBacklog
= new List<OrderByPropertyEntry>();
private OrderByProperty _orderByProperty = null;
private OrderByPropertyComparer _comparer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected override void ProcessRecord()
string owner = ConvertToNTAccount(rawSecurityDescriptor.Owner);
string group = ConvertToNTAccount(rawSecurityDescriptor.Group);

AccessRightTypeNames? typeToUse = _isTypeSet ? _type : (AccessRightTypeNames?) null;
AccessRightTypeNames? typeToUse = _isTypeSet ? _type : (AccessRightTypeNames?)null;
string[] discretionaryAcl = ConvertAccessControlListToStrings(rawSecurityDescriptor.DiscretionaryAcl, typeToUse);
string[] systemAcl = ConvertAccessControlListToStrings(rawSecurityDescriptor.SystemAcl, typeToUse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ public class ConvertFromMarkdownCommand : PSCmdlet
private const string PathParameterSet = "PathParamSet";
private const string LiteralPathParameterSet = "LiteralParamSet";
private const string InputObjParamSet = "InputObjParamSet";
private MarkdownConversionType conversionType = MarkdownConversionType.HTML;
private PSMarkdownOptionInfo mdOption = null;
private MarkdownConversionType _conversionType = MarkdownConversionType.HTML;
private PSMarkdownOptionInfo _mdOption = null;

/// <summary>
/// Read the PSMarkdownOptionInfo set in SessionState.
/// </summary>
protected override void BeginProcessing()
{
mdOption = this.CommandInfo.Module.SessionState.PSVariable.GetValue("PSMarkdownOptionInfo", new PSMarkdownOptionInfo()) as PSMarkdownOptionInfo;
_mdOption = this.CommandInfo.Module.SessionState.PSVariable.GetValue("PSMarkdownOptionInfo", new PSMarkdownOptionInfo()) as PSMarkdownOptionInfo;

if (mdOption == null)
if (_mdOption == null)
{
throw new InvalidOperationException();
}
Expand All @@ -79,12 +79,12 @@ protected override void BeginProcessing()
// supportsVT100 == false if host does not support VT100.
if (supportsVT100 != true)
{
mdOption.EnableVT100Encoding = false;
_mdOption.EnableVT100Encoding = false;
}

if (AsVT100EncodedString)
{
conversionType = MarkdownConversionType.VT100;
_conversionType = MarkdownConversionType.VT100;
}
}

Expand All @@ -103,12 +103,12 @@ protected override void ProcessRecord()
WriteObject(
MarkdownConverter.Convert(
ReadContentFromFile(fileInfo.FullName)?.Result,
conversionType,
mdOption));
_conversionType,
_mdOption));
}
else if (baseObj is string inpObj)
{
WriteObject(MarkdownConverter.Convert(inpObj, conversionType, mdOption));
WriteObject(MarkdownConverter.Convert(inpObj, _conversionType, _mdOption));
}
else
{
Expand All @@ -125,11 +125,11 @@ protected override void ProcessRecord()
break;

case PathParameterSet:
ConvertEachFile(Path, conversionType, isLiteral: false, optionInfo: mdOption);
ConvertEachFile(Path, _conversionType, isLiteral: false, optionInfo: _mdOption);
break;

case LiteralPathParameterSet:
ConvertEachFile(LiteralPath, conversionType, isLiteral: true, optionInfo: mdOption);
ConvertEachFile(LiteralPath, _conversionType, isLiteral: true, optionInfo: _mdOption);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected override void ProcessRecord()
}
}

private static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private static readonly DateTime s_epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

/// <summary>
/// This is more an implementation of the UNIX strftime.
Expand Down Expand Up @@ -454,7 +454,7 @@ private string UFormatDateString(DateTime dateTime)
break;

case 's':
sb.Append(StringUtil.Format("{0:0}", dateTime.ToUniversalTime().Subtract(epoch).TotalSeconds));
sb.Append(StringUtil.Format("{0:0}", dateTime.ToUniversalTime().Subtract(s_epoch).TotalSeconds));
break;

case 'T':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ private void WriteHashResult(string Algorithm, string hash, string path)
private const string PathParameterSet = "Path";
private const string LiteralPathParameterSet = "LiteralPath";
private const string StreamParameterSet = "StreamParameterSet";

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Microsoft.PowerShell.Commands
{

/// <summary>
/// Implementation of the Get Verb Command.
/// </summary>
Expand Down Expand Up @@ -41,7 +40,6 @@ public string[] Group
/// </summary>
protected override void ProcessRecord()
{

Type[] verbTypes = new Type[] { typeof(VerbsCommon), typeof(VerbsCommunications), typeof(VerbsData),
typeof(VerbsDiagnostic), typeof(VerbsLifecycle), typeof(VerbsOther), typeof(VerbsSecurity) };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ private void GenerateManifest(TextWriter writer, string psm1fileName, string for
CodeGeneration.EscapeSingleQuotedStringContent(StringUtil.Format(ImplicitRemotingStrings.ProxyModuleDescription, this.GetConnectionString())),
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(psm1fileName)),
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(formatPs1xmlFileName)),
this._remoteRunspaceInfo.InstanceId);
_remoteRunspaceInfo.InstanceId);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected override void EndProcessing()

this.CommandInfo.Module.SessionState.PSVariable.Set(MarkdownOptionInfoVariableName, mdOptionInfo);

if(PassThru.IsPresent)
if (PassThru.IsPresent)
{
WriteObject(mdOptionInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,10 +1064,10 @@ public string[] Include
// but we have to include it to silence OACR
_includeStrings = value ?? throw PSTraceSource.NewArgumentNullException(nameof(value));

this._include = new WildcardPattern[_includeStrings.Length];
_include = new WildcardPattern[_includeStrings.Length];
for (int i = 0; i < _includeStrings.Length; i++)
{
this._include[i] = WildcardPattern.Get(_includeStrings[i], WildcardOptions.IgnoreCase);
_include[i] = WildcardPattern.Get(_includeStrings[i], WildcardOptions.IgnoreCase);
}
}
}
Expand All @@ -1091,10 +1091,10 @@ public string[] Exclude
// but we have to include it to silence OACR
_excludeStrings = value ?? throw PSTraceSource.NewArgumentNullException("value");

this._exclude = new WildcardPattern[_excludeStrings.Length];
_exclude = new WildcardPattern[_excludeStrings.Length];
for (int i = 0; i < _excludeStrings.Length; i++)
{
this._exclude[i] = WildcardPattern.Get(_excludeStrings[i], WildcardOptions.IgnoreCase);
_exclude[i] = WildcardPattern.Get(_excludeStrings[i], WildcardOptions.IgnoreCase);
}
}
}
Expand Down Expand Up @@ -1615,11 +1615,11 @@ private bool DoMatchWorker(string operandString, MatchInfo matchInfo, out MatchI

// otherwise construct and populate a new MatchInfo object
matchResult = new MatchInfo
{
IgnoreCase = !CaseSensitive,
Line = operandString,
Pattern = Pattern[patternIndex]
};
{
IgnoreCase = !CaseSensitive,
Line = operandString,
Pattern = Pattern[patternIndex]
};

if (_preContext > 0 || _postContext > 0)
{
Expand Down Expand Up @@ -1758,9 +1758,9 @@ private bool MeetsIncludeExcludeCriteria(string filename)
bool ok = false;

// see if the file is on the include list...
if (this._include != null)
if (_include != null)
{
foreach (WildcardPattern patternItem in this._include)
foreach (WildcardPattern patternItem in _include)
{
if (patternItem.IsMatch(filename))
{
Expand All @@ -1780,9 +1780,9 @@ private bool MeetsIncludeExcludeCriteria(string filename)
}

// now see if it's on the exclude list...
if (this._exclude != null)
if (_exclude != null)
{
foreach (WildcardPattern patternItem in this._exclude)
foreach (WildcardPattern patternItem in _exclude)
{
if (patternItem.IsMatch(filename))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ public ByteCollection(byte[] value)
[Obsolete("The property is deprecated, please use Offset64 instead.", true)]
public UInt32 Offset
{
get
{
get
{
return (UInt32)Offset64;
}
}

private set
{
Offset64 = value;
}
private set
{
Offset64 = value;
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,6 @@ public HttpResponseException(string message, HttpResponseMessage response) : bas
/// </summary>
public abstract partial class WebRequestPSCmdlet : PSCmdlet
{

/// <summary>
/// Gets or sets the PreserveAuthorizationOnRedirect property.
/// </summary>
Expand Down Expand Up @@ -1107,7 +1106,6 @@ internal virtual HttpRequestMessage GetRequest(Uri uri)
{
request.Headers.Add(HttpKnownHeaderNames.UserAgent, WebSession.UserAgent);
}

}

// Set 'Keep-Alive' to false. This means set the Connection to 'Close'.
Expand Down Expand Up @@ -1790,7 +1788,6 @@ internal long SetRequestContent(HttpRequestMessage request, IDictionary content)

string body = FormatDictionary(content);
return (SetRequestContent(request, body));

}

internal void ParseLinkHeader(HttpResponseMessage response, System.Uri requestUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ConvertToJsonCommand : PSCmdlet

private int _depth = 2;
private const int maxDepthAllowed = 100;
private readonly CancellationTokenSource cancellationSource = new CancellationTokenSource();
private readonly CancellationTokenSource _cancellationSource = new CancellationTokenSource();

/// <summary>
/// Gets or sets the Depth property.
Expand Down Expand Up @@ -119,7 +119,7 @@ protected override void EndProcessing()
Depth,
EnumsAsStrings.IsPresent,
Compress.IsPresent,
cancellationSource.Token,
_cancellationSource.Token,
EscapeHandling,
targetCmdlet: this);

Expand All @@ -138,7 +138,7 @@ protected override void EndProcessing()
/// </summary>
protected override void StopProcessing()
{
cancellationSource.Cancel();
_cancellationSource.Cancel();
}
}
}
Loading