From ac53dff089159b75b65f980dafdb4bfd02da079f Mon Sep 17 00:00:00 2001 From: kwkam Date: Wed, 14 Mar 2018 02:18:49 +0800 Subject: [PATCH] Minor code clean-up changes (#5737) --- .../engine/CommandCompletion/CompletionCompleters.cs | 10 +++------- .../engine/parser/TypeInferenceVisitor.cs | 2 +- .../help/HelpCommentsParser.cs | 2 +- .../namespaces/FileSystemProvider.cs | 8 ++++---- .../namespaces/NavigationProviderBase.cs | 4 ++-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 4a1363c91c..474f0f941a 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -4257,7 +4257,7 @@ namespace System.Management.Automation { var sessionStateInternal = executionContext.EngineSessionState; completionText = sessionStateInternal.NormalizeRelativePath(path, sessionStateInternal.CurrentLocation.ProviderPath); - string parentDirectory = ".." + Path.DirectorySeparatorChar; + string parentDirectory = ".." + StringLiterals.DefaultPathSeparator; if (!completionText.StartsWith(parentDirectory, StringComparison.Ordinal)) completionText = Path.Combine(".", completionText); } @@ -4472,13 +4472,9 @@ namespace System.Management.Automation var wordToComplete = context.WordToComplete; var colon = wordToComplete.IndexOf(':'); - var prefix = "$"; var lastAst = context.RelatedAsts.Last(); var variableAst = lastAst as VariableExpressionAst; - if (variableAst != null && variableAst.Splatted) - { - prefix = "@"; - } + var prefix = variableAst != null && variableAst.Splatted ? "@" : "$"; // Look for variables in the input (e.g. parameters, etc.) before checking session state - these // variables might not exist in session state yet. @@ -5923,7 +5919,7 @@ namespace System.Management.Automation internal static List CompleteHelpTopics(CompletionContext context) { var results = new List(); - var dirPath = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID) + Path.DirectorySeparatorChar + CultureInfo.CurrentCulture.Name; + var dirPath = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID) + StringLiterals.DefaultPathSeparator + CultureInfo.CurrentCulture.Name; var wordToComplete = context.WordToComplete + "*"; var topicPattern = WildcardPattern.Get("about_*.help.txt", WildcardOptions.IgnoreCase); List files = new List(); diff --git a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs index b488a4cbd5..91b3a5f5b9 100644 --- a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs +++ b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs @@ -423,7 +423,7 @@ namespace System.Management.Automation { private readonly TypeInferenceContext _context; - private static readonly PSTypeName StringPSTypeName = new PSTypeName(typeof(string)); + private static readonly PSTypeName StringPSTypeName = new PSTypeName(typeof(string)); public TypeInferenceVisitor(TypeInferenceContext context) { diff --git a/src/System.Management.Automation/help/HelpCommentsParser.cs b/src/System.Management.Automation/help/HelpCommentsParser.cs index 317620d1b2..e527879eb3 100644 --- a/src/System.Management.Automation/help/HelpCommentsParser.cs +++ b/src/System.Management.Automation/help/HelpCommentsParser.cs @@ -353,7 +353,7 @@ namespace System.Management.Automation // The title is automatically generated XmlElement title = _doc.CreateElement("maml:title", mamlURI); string titleStr = string.Format(CultureInfo.InvariantCulture, - " -------------------------- {0} {1} --------------------------", + "\t\t\t\t-------------------------- {0} {1} --------------------------", HelpDisplayStrings.ExampleUpperCase, count++); XmlText title_text = _doc.CreateTextNode(titleStr); example_node.AppendChild(title).AppendChild(title_text); diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 0b332eeb5c..4648f6a605 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -4981,13 +4981,13 @@ namespace Microsoft.PowerShell.Commands try { string originalPathComparison = path; - if (!originalPathComparison.EndsWith("" + StringLiterals.DefaultPathSeparator, StringComparison.OrdinalIgnoreCase)) + if (!originalPathComparison.EndsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.OrdinalIgnoreCase)) { originalPathComparison += StringLiterals.DefaultPathSeparator; } string basePathComparison = basePath; - if (!basePathComparison.EndsWith("" + StringLiterals.DefaultPathSeparator, StringComparison.OrdinalIgnoreCase)) + if (!basePathComparison.EndsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.OrdinalIgnoreCase)) { basePathComparison += StringLiterals.DefaultPathSeparator; } @@ -5190,7 +5190,7 @@ namespace Microsoft.PowerShell.Commands // See if the base and the path are already the same. We resolve this to // ..\Leaf, since resolving "." to "." doesn't offer much information. if (String.Equals(path, basePath, StringComparison.OrdinalIgnoreCase) && - (!originalPath.EndsWith("" + StringLiterals.DefaultPathSeparator, StringComparison.OrdinalIgnoreCase))) + (!originalPath.EndsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.OrdinalIgnoreCase))) { string childName = GetChildName(path); result = MakePath("..", childName); @@ -5237,7 +5237,7 @@ namespace Microsoft.PowerShell.Commands if (!String.IsNullOrEmpty(commonBase)) { if (String.Equals(path, commonBase, StringComparison.OrdinalIgnoreCase) && - (!path.EndsWith("" + StringLiterals.DefaultPathSeparator, StringComparison.OrdinalIgnoreCase))) + (!path.EndsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.OrdinalIgnoreCase))) { string childName = GetChildName(path); result = MakePath("..", result); diff --git a/src/System.Management.Automation/namespaces/NavigationProviderBase.cs b/src/System.Management.Automation/namespaces/NavigationProviderBase.cs index 14f6ed59fd..3f56bd7ac4 100644 --- a/src/System.Management.Automation/namespaces/NavigationProviderBase.cs +++ b/src/System.Management.Automation/namespaces/NavigationProviderBase.cs @@ -663,7 +663,7 @@ namespace System.Management.Automation.Provider // See if the base and the path are already the same. We resolve this to // ..\Leaf, since resolving "." to "." doesn't offer much information. if (String.Equals(normalizedPath, normalizedBasePath, StringComparison.OrdinalIgnoreCase) && - (!originalPath.EndsWith("" + StringLiterals.DefaultPathSeparator, StringComparison.OrdinalIgnoreCase))) + (!originalPath.EndsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.OrdinalIgnoreCase))) { string childName = GetChildName(path); result = MakePath("..", childName); @@ -703,7 +703,7 @@ namespace System.Management.Automation.Provider if (!String.IsNullOrEmpty(commonBase)) { if (String.Equals(normalizedPath, commonBase, StringComparison.OrdinalIgnoreCase) && - (!normalizedPath.EndsWith("" + StringLiterals.DefaultPathSeparator, StringComparison.OrdinalIgnoreCase))) + (!normalizedPath.EndsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.OrdinalIgnoreCase))) { string childName = GetChildName(path); result = MakePath("..", result);