Mark private members as static part 10 (#14235)

https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822
This commit is contained in:
xtqqczze 2020-11-27 08:16:31 +00:00 committed by GitHub
parent c909541b77
commit 8d4869372e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 53 additions and 53 deletions

View file

@ -393,7 +393,7 @@ namespace System.Management.Automation
}
// Find the assembly under 'gacRoot' and select the latest version.
private bool FindInGac(string gacRoot, AssemblyName assemblyName, out string assemblyPath)
private static bool FindInGac(string gacRoot, AssemblyName assemblyName, out string assemblyPath)
{
bool assemblyFound = false;
assemblyPath = null;
@ -430,7 +430,7 @@ namespace System.Management.Automation
/// <summary>
/// Try to get the specified assembly from cache.
/// </summary>
private bool TryGetAssemblyFromCache(AssemblyName assemblyName, out Assembly asmLoaded)
private static bool TryGetAssemblyFromCache(AssemblyName assemblyName, out Assembly asmLoaded)
{
if (s_assemblyCache.TryGetValue(assemblyName.Name, out asmLoaded))
{
@ -454,7 +454,7 @@ namespace System.Management.Automation
/// <param name="requestedAssembly">AssemblyName of the requested assembly.</param>
/// <param name="loadedAssembly">AssemblyName of the loaded assembly.</param>
/// <returns></returns>
private bool IsAssemblyMatching(AssemblyName requestedAssembly, AssemblyName loadedAssembly)
private static bool IsAssemblyMatching(AssemblyName requestedAssembly, AssemblyName loadedAssembly)
{
//
// We use the same rules as CoreCLR loader to compare the requested assembly and loaded assembly:
@ -501,7 +501,7 @@ namespace System.Management.Automation
/// <param name="tpaStrongName">
/// The assembly strong name of a CoreCLR Trusted_Platform_Assembly
/// </param>
private Assembly GetTrustedPlatformAssembly(string tpaStrongName)
private static Assembly GetTrustedPlatformAssembly(string tpaStrongName)
{
// We always depend on the default context to load the TPAs that are recorded in
// the type catalog.
@ -517,7 +517,7 @@ namespace System.Management.Automation
/// <summary>
/// Throw FileLoadException.
/// </summary>
private void ThrowFileLoadException(string errorTemplate, params object[] args)
private static void ThrowFileLoadException(string errorTemplate, params object[] args)
{
string message = string.Format(CultureInfo.CurrentCulture, errorTemplate, args);
throw new FileLoadException(message);
@ -526,7 +526,7 @@ namespace System.Management.Automation
/// <summary>
/// Throw FileNotFoundException.
/// </summary>
private void ThrowFileNotFoundException(string errorTemplate, params object[] args)
private static void ThrowFileNotFoundException(string errorTemplate, params object[] args)
{
string message = string.Format(CultureInfo.CurrentCulture, errorTemplate, args);
throw new FileNotFoundException(message);

View file

@ -100,7 +100,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
WriteToTracer(entry);
}
private void WriteToTracer(XmlLoaderLoggerEntry entry)
private static void WriteToTracer(XmlLoaderLoggerEntry entry)
{
if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error)
{

View file

@ -176,7 +176,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
return retVal;
}
private Assembly ResolveAssemblyNameInLoadedAssemblies(string assemblyName, bool fullName)
private static Assembly ResolveAssemblyNameInLoadedAssemblies(string assemblyName, bool fullName)
{
Assembly result = null;

View file

@ -219,7 +219,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
return BestMatchIndexUndefined;
}
private bool MatchCondition(PSObject currentObject, PSPropertyExpression ex)
private static bool MatchCondition(PSObject currentObject, PSPropertyExpression ex)
{
if (ex == null)
return true;

View file

@ -586,7 +586,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
/// </summary>
/// <param name="tableBody"></param>
/// <param name="headers"></param>
private void LoadHeadersSectionFromObjectModel(TableControlBody tableBody, List<TableControlColumnHeader> headers)
private static void LoadHeadersSectionFromObjectModel(TableControlBody tableBody, List<TableControlColumnHeader> headers)
{
foreach (TableControlColumnHeader header in headers)
{
@ -746,7 +746,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
/// Load EntrySelectedBy (TypeName) into AppliesTo.
/// </summary>
/// <returns></returns>
private AppliesTo LoadAppliesToSectionFromObjectModel(List<string> selectedBy, List<DisplayEntry> condition)
private static AppliesTo LoadAppliesToSectionFromObjectModel(List<string> selectedBy, List<DisplayEntry> condition)
{
AppliesTo appliesTo = new AppliesTo();

View file

@ -354,7 +354,7 @@ namespace Microsoft.PowerShell.Commands
}
}
private PSObject IfHashtableWrapAsPSCustomObject(PSObject target, out bool wrapped)
private static PSObject IfHashtableWrapAsPSCustomObject(PSObject target, out bool wrapped)
{
wrapped = false;

View file

@ -234,7 +234,7 @@ function __cmdletization_BindCommonParameters
return verb + "-" + noun;
}
private string GetCmdletAttributes(CommonCmdletMetadata cmdletMetadata)
private static string GetCmdletAttributes(CommonCmdletMetadata cmdletMetadata)
{
// Generate the script for the Alias and Obsolete Attribute if any is declared in CDXML
StringBuilder attributes = new StringBuilder(150);
@ -1444,7 +1444,7 @@ function __cmdletization_BindCommonParameters
}
}
private void GenerateIfBoundParameter(
private static void GenerateIfBoundParameter(
IEnumerable<string> commonParameterSets,
IEnumerable<string> methodParameterSets,
ParameterMetadata cmdletParameterMetadata,
@ -1874,7 +1874,7 @@ Microsoft.PowerShell.Core\Export-ModuleMember -Function '{1}' -Alias '*'
private void WriteCmdlet(TextWriter output, StaticCmdletMetadata staticCmdlet)
{
string attributeString = this.GetCmdletAttributes(staticCmdlet.CmdletMetadata);
string attributeString = GetCmdletAttributes(staticCmdlet.CmdletMetadata);
Dictionary<string, ParameterMetadata> commonParameters = this.GetCommonParameters();
List<string> commonParameterSets = GetCommonParameterSets(commonParameters);
@ -1959,7 +1959,7 @@ Microsoft.PowerShell.Core\Export-ModuleMember -Function '{1}' -Alias '*'
private void WriteCmdlet(TextWriter output, InstanceCmdletMetadata instanceCmdlet)
{
string attributeString = this.GetCmdletAttributes(instanceCmdlet.CmdletMetadata);
string attributeString = GetCmdletAttributes(instanceCmdlet.CmdletMetadata);
Dictionary<string, ParameterMetadata> commonParameters = this.GetCommonParameters();
List<string> commonParameterSets = GetCommonParameterSets(commonParameters);
@ -2066,7 +2066,7 @@ Microsoft.PowerShell.Core\Export-ModuleMember -Function '{1}' -Alias '*'
CommonCmdletMetadata cmdletMetadata = this.GetGetCmdletMetadata();
Dbg.Assert(cmdletMetadata != null, "xsd should ensure that cmdlet metadata element is always present");
CommandMetadata commandMetadata = this.GetCommandMetadata(cmdletMetadata);
string attributeString = this.GetCmdletAttributes(cmdletMetadata);
string attributeString = GetCmdletAttributes(cmdletMetadata);
GetCmdletParameters getCmdletParameters = this.GetGetCmdletParameters(null);
if (!string.IsNullOrEmpty(getCmdletParameters.DefaultCmdletParameterSet))

View file

@ -242,7 +242,7 @@ namespace Microsoft.PowerShell.Cim
throw new ArgumentNullException(nameof(adaptedProperty));
}
private void AddTypeNameHierarchy(IList<string> typeNamesWithNamespace, IList<string> typeNamesWithoutNamespace, string namespaceName, string className)
private static void AddTypeNameHierarchy(IList<string> typeNamesWithNamespace, IList<string> typeNamesWithoutNamespace, string namespaceName, string className)
{
if (!string.IsNullOrEmpty(namespaceName))
{
@ -258,7 +258,7 @@ namespace Microsoft.PowerShell.Cim
className));
}
private List<CimClass> GetInheritanceChain(CimInstance cimInstance)
private static List<CimClass> GetInheritanceChain(CimInstance cimInstance)
{
List<CimClass> inheritanceChain = new List<CimClass>();
CimClass cimClass = cimInstance.CimClass;

View file

@ -84,7 +84,7 @@ namespace System.Management.Automation
#region Help Provider Interface
private void GetModulePaths(CommandInfo commandInfo, out string moduleName, out string moduleDir, out string nestedModulePath)
private static void GetModulePaths(CommandInfo commandInfo, out string moduleName, out string moduleDir, out string nestedModulePath)
{
Dbg.Assert(commandInfo != null, "Caller should verify that commandInfo != null");
@ -132,7 +132,7 @@ namespace System.Management.Automation
}
}
private string GetHelpName(CommandInfo commandInfo)
private static string GetHelpName(CommandInfo commandInfo)
{
Dbg.Assert(commandInfo != null, "Caller should verify that commandInfo != null");

View file

@ -268,7 +268,7 @@ namespace System.Management.Automation
}
}
private void GetModuleNameAndVersion(string psmodulePathRoot, string filePath, out string moduleName, out Version moduleVersion)
private static void GetModuleNameAndVersion(string psmodulePathRoot, string filePath, out string moduleName, out Version moduleVersion)
{
moduleVersion = null;
moduleName = null;

View file

@ -113,7 +113,7 @@ namespace System.Management.Automation
}
}
private string[] GetFiles(string path, string pattern)
private static string[] GetFiles(string path, string pattern)
{
#if UNIX
// On Linux, file names are case sensitive, so we need to add

View file

@ -646,7 +646,7 @@ namespace System.Management.Automation
/// </summary>
/// <param name="nodes"></param>
/// <returns></returns>
private int GetParaMamlNodeCount(XmlNodeList nodes)
private static int GetParaMamlNodeCount(XmlNodeList nodes)
{
int i = 0;

View file

@ -484,7 +484,7 @@ namespace Microsoft.PowerShell.Commands
return inputData;
}
private bool TryConvertFromDeserializedModuleInfo(object inputData, out PSModuleInfo moduleInfo)
private static bool TryConvertFromDeserializedModuleInfo(object inputData, out PSModuleInfo moduleInfo)
{
moduleInfo = null;
PSObject pso = inputData as PSObject;

View file

@ -621,7 +621,7 @@ namespace System.Management.Automation.Help
/// <param name="schema">Xml schema.</param>
/// <param name="handler">Validation event handler.</param>
/// <param name="helpInfo">HelpInfo or HelpContent?</param>
private XmlDocument CreateValidXmlDocument(string xml, string ns, string schema, ValidationEventHandler handler,
private static XmlDocument CreateValidXmlDocument(string xml, string ns, string schema, ValidationEventHandler handler,
bool helpInfo)
{
XmlReaderSettings settings = new XmlReaderSettings();
@ -998,7 +998,7 @@ namespace System.Management.Automation.Help
/// Removes the read only attribute.
/// </summary>
/// <param name="path"></param>
private void RemoveReadOnly(string path)
private static void RemoveReadOnly(string path)
{
if (File.Exists(path))
{
@ -1093,7 +1093,7 @@ namespace System.Management.Automation.Help
}
#if UNIX
private bool ExpandArchive(string source, string destination)
private static bool ExpandArchive(string source, string destination)
{
bool sucessfulDecompression = false;
@ -1125,7 +1125,7 @@ namespace System.Management.Automation.Help
/// <param name="srcPath">Source path.</param>
/// <param name="destPath">Destination path.</param>
/// <param name="needToCopy">Is set to false if we find a single file placeholder.txt in cab. This means we no longer need to install help files.</param>
private void UnzipHelpContent(ExecutionContext context, string srcPath, string destPath, out bool needToCopy)
private static void UnzipHelpContent(ExecutionContext context, string srcPath, string destPath, out bool needToCopy)
{
needToCopy = true;

View file

@ -488,7 +488,7 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
/// <param name="path"></param>
/// <param name="e"></param>
private void ThrowPathMustBeValidContainersException(string path, Exception e)
private static void ThrowPathMustBeValidContainersException(string path, Exception e)
{
throw new UpdatableHelpSystemException("PathMustBeValidContainers",
StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, path), ErrorCategory.InvalidArgument,

View file

@ -709,7 +709,7 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
/// <param name="drive"></param>
/// <returns></returns>
private bool IsNetworkMappedDrive(PSDriveInfo drive)
private static bool IsNetworkMappedDrive(PSDriveInfo drive)
{
bool shouldMapNetworkDrive = (drive != null && !string.IsNullOrEmpty(drive.Root) && PathIsNetworkPath(drive.Root)) &&
(drive.Persist || (drive.Credential != null && !drive.Credential.Equals(PSCredential.Empty)));
@ -789,7 +789,7 @@ namespace Microsoft.PowerShell.Commands
/// PS Drive Info.
/// </param>
/// <returns>True if the drive can be persisted or else false.</returns>
private bool IsSupportedDriveForPersistence(PSDriveInfo drive)
private static bool IsSupportedDriveForPersistence(PSDriveInfo drive)
{
bool isSupportedDriveForPersistence = false;
if (drive != null && !string.IsNullOrEmpty(drive.Name) && drive.Name.Length == 1)
@ -4203,7 +4203,7 @@ namespace Microsoft.PowerShell.Commands
SafeInvokeCommand.Invoke(ps, this, null, false);
}
private bool ValidRemoteSessionForScripting(Runspace runspace)
private static bool ValidRemoteSessionForScripting(Runspace runspace)
{
if (runspace is not RemoteRunspace)
{
@ -4768,7 +4768,7 @@ namespace Microsoft.PowerShell.Commands
// Returns a hash table with metadata about this file info.
//
private Hashtable GetFileMetadata(FileInfo file)
private static Hashtable GetFileMetadata(FileInfo file)
{
Hashtable metadata = new Hashtable();
@ -6137,7 +6137,7 @@ namespace Microsoft.PowerShell.Commands
}
#if !UNIX
private bool IsSameWindowsVolume(string source, string destination)
private static bool IsSameWindowsVolume(string source, string destination)
{
FileInfo src = new FileInfo(source);
FileInfo dest = new FileInfo(destination);

View file

@ -2272,7 +2272,7 @@ namespace System.Management.Automation
return driveRootRelativeWorkingPath;
}
private bool HasRelativePathTokens(string path)
private static bool HasRelativePathTokens(string path)
{
string comparePath = path.Replace('/', '\\');

View file

@ -2956,7 +2956,7 @@ namespace Microsoft.PowerShell.Commands
return result;
}
private bool HasRelativePathTokens(string path)
private static bool HasRelativePathTokens(string path)
{
return (
path.StartsWith('\\') ||
@ -3195,7 +3195,7 @@ namespace Microsoft.PowerShell.Commands
/// <returns>
/// true if the path is empty, a \ or a /, else false
/// </returns>
private bool IsHiveContainer(string path)
private static bool IsHiveContainer(string path)
{
bool result = false;
if (path == null)
@ -4114,7 +4114,7 @@ namespace Microsoft.PowerShell.Commands
/// <returns>
/// A string containing the default value name.
/// </returns>
private string LocalizedDefaultToken => "(default)";
private static string LocalizedDefaultToken => "(default)";
/// <summary>
/// Converts an empty or null userEnteredPropertyName to the localized

View file

@ -368,7 +368,7 @@ namespace Microsoft.PowerShell
return policyCheckPassed;
}
private bool SetPolicyFromAuthenticodePrompt(string path, PSHost host, ref Exception reason, Signature signature)
private static bool SetPolicyFromAuthenticodePrompt(string path, PSHost host, ref Exception reason, Signature signature)
{
bool policyCheckPassed = false;
@ -405,7 +405,7 @@ namespace Microsoft.PowerShell
return policyCheckPassed;
}
private bool IsLocalFile(string filename)
private static bool IsLocalFile(string filename)
{
#if UNIX
return true;
@ -425,7 +425,7 @@ namespace Microsoft.PowerShell
// Checks that a publisher is trusted by the system or is one of
// the signed product binaries
private bool IsTrustedPublisher(Signature signature, string file)
private static bool IsTrustedPublisher(Signature signature, string file)
{
// Get the thumbprint of the current signature
X509Certificate2 signerCertificate = signature.SignerCertificate;
@ -444,7 +444,7 @@ namespace Microsoft.PowerShell
return false;
}
private bool IsUntrustedPublisher(Signature signature, string file)
private static bool IsUntrustedPublisher(Signature signature, string file)
{
// Get the thumbprint of the current signature
X509Certificate2 signerCertificate = signature.SignerCertificate;
@ -467,7 +467,7 @@ namespace Microsoft.PowerShell
/// Trust a publisher by adding it to the "Trusted Publishers" store.
/// </summary>
/// <param name="signature"></param>
private void TrustPublisher(Signature signature)
private static void TrustPublisher(Signature signature)
{
// Get the certificate of the signer
X509Certificate2 signerCertificate = signature.SignerCertificate;
@ -485,7 +485,7 @@ namespace Microsoft.PowerShell
}
}
private void UntrustPublisher(Signature signature)
private static void UntrustPublisher(Signature signature)
{
// Get the certificate of the signer
X509Certificate2 signerCertificate = signature.SignerCertificate;
@ -516,7 +516,7 @@ namespace Microsoft.PowerShell
}
}
private Signature GetSignatureWithEncodingRetry(string path, ExternalScriptInfo script)
private static Signature GetSignatureWithEncodingRetry(string path, ExternalScriptInfo script)
{
string verificationContents = System.Text.Encoding.Unicode.GetString(script.OriginalEncoding.GetPreamble()) + script.ScriptContents;
Signature signature = SignatureHelper.GetSignature(path, verificationContents);
@ -640,7 +640,7 @@ namespace Microsoft.PowerShell
return allowRun;
}
private RunPromptDecision AuthenticodePrompt(string path,
private static RunPromptDecision AuthenticodePrompt(string path,
Signature signature,
PSHost host)
{
@ -713,7 +713,7 @@ namespace Microsoft.PowerShell
return decision;
}
private RunPromptDecision RemoteFilePrompt(string path, PSHost host)
private static RunPromptDecision RemoteFilePrompt(string path, PSHost host)
{
if ((host == null) || (host.UI == null))
{
@ -743,7 +743,7 @@ namespace Microsoft.PowerShell
}
}
private Collection<ChoiceDescription> GetAuthenticodePromptChoices()
private static Collection<ChoiceDescription> GetAuthenticodePromptChoices()
{
Collection<ChoiceDescription> choices = new Collection<ChoiceDescription>();
@ -764,7 +764,7 @@ namespace Microsoft.PowerShell
return choices;
}
private Collection<ChoiceDescription> GetRemoteFilePromptChoices()
private static Collection<ChoiceDescription> GetRemoteFilePromptChoices()
{
Collection<ChoiceDescription> choices = new Collection<ChoiceDescription>();

View file

@ -617,7 +617,7 @@ namespace System.Management.Automation.Internal
}
}
private ReturnType ConvertToReturnType(object inputObject)
private static ReturnType ConvertToReturnType(object inputObject)
{
Type resultType = typeof(ReturnType);
if (typeof(PSObject) == resultType || typeof(object) == resultType)
@ -793,7 +793,7 @@ namespace System.Management.Automation.Internal
/// </summary>
/// <param name="inputObject">Input object to convert.</param>
/// <returns>Input object converted to the specified return type.</returns>
private ReturnType ConvertToReturnType(object inputObject)
private static ReturnType ConvertToReturnType(object inputObject)
{
Type resultType = typeof(ReturnType);
if (typeof(PSObject) == resultType || typeof(object) == resultType)

View file

@ -988,7 +988,7 @@ namespace System.Management.Automation.Tracing
/// </summary>
public PowerShellTraceTask Task { get; set; } = PowerShellTraceTask.None;
private bool IsEtwSupported
private static bool IsEtwSupported
{
get
{