GeezerVison is showing github.com — Cleanup: Use EndsWith(char) and StartsWith(char) (#9994) · Thatgfsj-contribs/PowerShell@05242d7
File treeExpand file treeCollapse file tree Open diff view settings Microsoft.PowerShell.Commands.Diagnostics Microsoft.PowerShell.Commands.Management/commands/management Microsoft.PowerShell.Commands.Utility/commands/utility Microsoft.PowerShell.ConsoleHost/host/msh Microsoft.WSMan.Management System.Management.Automation
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1294,7 +1294,7 @@ private string BuildStructuredQueryFromHashTable(EventLogSession eventLogSession | 1294 | 1294 | string query = queriedLogsQueryMap[keyLogName]; | 1295 | 1295 | result.Append(query); | 1296 | 1296 |
| 1297 | | - if (query.EndsWith("*", StringComparison.OrdinalIgnoreCase)) | | 1297 | + if (query.EndsWith('*')) | 1298 | 1298 | { | 1299 | 1299 | // | 1300 | 1300 | // No provider predicate: just add the XPath string | |
Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Management/commands/management/ClearRecycleBinCommand.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -171,7 +171,7 @@ private string GetDrivePath(string driveName) | 171 | 171 | { | 172 | 172 | drivePath = driveName; | 173 | 173 | } | 174 | | - else if (driveName.EndsWith(":", StringComparison.OrdinalIgnoreCase)) | | 174 | + else if (driveName.EndsWith(':')) | 175 | 175 | { | 176 | 176 | drivePath = driveName + "\\"; | 177 | 177 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1898,7 +1898,7 @@ internal static bool ContainsSystemDrive(string[] drives, string sysdrive) | 1898 | 1898 | string driveApp; | 1899 | 1899 | foreach (string drive in drives) | 1900 | 1900 | { | 1901 | | - if (!drive.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) | | 1901 | + if (!drive.EndsWith('\\')) | 1902 | 1902 | { | 1903 | 1903 | driveApp = string.Concat(drive, "\\"); | 1904 | 1904 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Management/commands/management/ResolvePathCommand.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -123,7 +123,7 @@ protected override void ProcessRecord() | 123 | 123 | // Do not insert './' if result path is not relative | 124 | 124 | if (!adjustedPath.StartsWith( | 125 | 125 | currentPath.Drive?.Root ?? currentPath.Path, StringComparison.OrdinalIgnoreCase) && | 126 | | - !adjustedPath.StartsWith(".", StringComparison.OrdinalIgnoreCase)) | | 126 | + !adjustedPath.StartsWith('.')) | 127 | 127 | { | 128 | 128 | adjustedPath = SessionState.Path.Combine(".", adjustedPath); | 129 | 129 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1301,7 +1301,7 @@ internal void ReadHeader() | 1301 | 1301 | values[0] = values[0].Substring(9); | 1302 | 1302 | Header = values; | 1303 | 1303 | } | 1304 | | - else if (values.Count != 0 && values[0].StartsWith("#")) | | 1304 | + else if (values.Count != 0 && values[0].StartsWith('#')) | 1305 | 1305 | { | 1306 | 1306 | // Skip all lines starting with '#' | 1307 | 1307 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1160,7 +1160,7 @@ bool TryGetBoolValue(string arg, out bool boolValue) | 1160 | 1160 |
| 1161 | 1161 | if (!System.IO.File.Exists(_file)) | 1162 | 1162 | { | 1163 | | - if (args[i].StartsWith("-") && args[i].Length > 1) | | 1163 | + if (args[i].StartsWith('-') && args[i].Length > 1) | 1164 | 1164 | { | 1165 | 1165 | string param = args[i].Substring(1, args[i].Length - 1).ToLower(); | 1166 | 1166 | StringBuilder possibleParameters = new StringBuilder(); | |
Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.WSMan.Management/ConfigProvider.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2969,7 +2969,7 @@ private string GetFilterString(Hashtable cmdlinevalues, string[] pkey) | 2969 | 2969 | } | 2970 | 2970 | } | 2971 | 2971 |
| 2972 | | - if (filter.ToString().EndsWith("+", StringComparison.OrdinalIgnoreCase)) | | 2972 | + if (filter.ToString().EndsWith('+')) | 2973 | 2973 | filter.Remove(filter.ToString().Length - 1, 1); | 2974 | 2974 | return filter.ToString(); | 2975 | 2975 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/Microsoft.WSMan.Management/WsManHelper.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -922,7 +922,7 @@ internal string GetURIWithFilter(string uri, string filter, Hashtable selectorse | 922 | 922 | if (operation.Equals("remove", StringComparison.OrdinalIgnoreCase)) | 923 | 923 | { | 924 | 924 | sburi.Append(GetFilterString(selectorset)); | 925 | | - if (sburi.ToString().EndsWith("?", StringComparison.OrdinalIgnoreCase)) | | 925 | + if (sburi.ToString().EndsWith('?')) | 926 | 926 | { | 927 | 927 | sburi.Remove(sburi.Length - 1, 1); | 928 | 928 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -887,7 +887,7 @@ internal static List<CompletionResult> PSv2GenerateMatchSetOfFiles(PowerShellExe | 887 | 887 |
| 888 | 888 | lastWord = lastWord ?? string.Empty; | 889 | 889 | bool isLastWordEmpty = string.IsNullOrEmpty(lastWord); | 890 | | - bool lastCharIsStar = !isLastWordEmpty && lastWord.EndsWith("*", StringComparison.Ordinal); | | 890 | + bool lastCharIsStar = !isLastWordEmpty && lastWord.EndsWith('*'); | 891 | 891 | bool containsGlobChars = WildcardPattern.ContainsWildcardCharacters(lastWord); | 892 | 892 |
| 893 | 893 | string wildWord = lastWord + "*"; | @@ -1045,9 +1045,9 @@ private static bool PSv2ShouldFullyQualifyPathsPath(PowerShellExecutionHelper he | 1045 | 1045 | { | 1046 | 1046 | // These are special cases, as they represent cases where the user expects to | 1047 | 1047 | // see the full path. | 1048 | | - if (lastWord.StartsWith("~", StringComparison.OrdinalIgnoreCase) || | 1049 | | - lastWord.StartsWith("\\", StringComparison.OrdinalIgnoreCase) || | 1050 | | - lastWord.StartsWith("/", StringComparison.OrdinalIgnoreCase)) | | 1048 | + if (lastWord.StartsWith('~') || | | 1049 | + lastWord.StartsWith('\\') || | | 1050 | + lastWord.StartsWith('/')) | 1051 | 1051 | { | 1052 | 1052 | return true; | 1053 | 1053 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -387,7 +387,7 @@ internal List<CompletionResult> GetResultHelper(CompletionContext completionCont | 387 | 387 | } | 388 | 388 |
| 389 | 389 | // Handle scenarios like this: dir -path:<tab> | 390 | | - if (completionContext.WordToComplete.EndsWith(":", StringComparison.Ordinal)) | | 390 | + if (completionContext.WordToComplete.EndsWith(':')) | 391 | 391 | { | 392 | 392 | replacementIndex = tokenAtCursor.Extent.EndScriptPosition.Offset; | 393 | 393 | replacementLength = 0; | |
|