From 744127608efdb07b800407c78b2a58434943e42b Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:45:33 +0000 Subject: [PATCH] Replace `Requires.NotNullOrEmpty(string)` with `ArgumentException.ThrowIfNullOrEmpty` (#19197) --- .../Subsystem/FeedbackSubsystem/IFeedbackProvider.cs | 2 +- .../Subsystem/PredictionSubsystem/CommandPrediction.cs | 2 +- .../Subsystem/PredictionSubsystem/ICommandPredictor.cs | 4 ++-- src/System.Management.Automation/engine/Utils.cs | 8 -------- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/System.Management.Automation/engine/Subsystem/FeedbackSubsystem/IFeedbackProvider.cs b/src/System.Management.Automation/engine/Subsystem/FeedbackSubsystem/IFeedbackProvider.cs index 52c79a46fd..0e126f9f27 100644 --- a/src/System.Management.Automation/engine/Subsystem/FeedbackSubsystem/IFeedbackProvider.cs +++ b/src/System.Management.Automation/engine/Subsystem/FeedbackSubsystem/IFeedbackProvider.cs @@ -89,7 +89,7 @@ namespace System.Management.Automation.Subsystem.Feedback /// The layout for displaying the actions. public FeedbackItem(string header, List? actions, string? footer, FeedbackDisplayLayout layout) { - Requires.NotNullOrEmpty(header, nameof(header)); + ArgumentException.ThrowIfNullOrEmpty(header); Header = header; RecommendedActions = actions; diff --git a/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/CommandPrediction.cs b/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/CommandPrediction.cs index dcafbbc623..3e06d04648 100644 --- a/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/CommandPrediction.cs +++ b/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/CommandPrediction.cs @@ -249,7 +249,7 @@ namespace System.Management.Automation.Subsystem.Prediction /// The accepted suggestion text. public static void OnSuggestionAccepted(PredictionClient client, Guid predictorId, uint session, string suggestionText) { - Requires.NotNullOrEmpty(suggestionText, nameof(suggestionText)); + ArgumentException.ThrowIfNullOrEmpty(suggestionText); var predictors = SubsystemManager.GetSubsystems(); if (predictors.Count == 0) diff --git a/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/ICommandPredictor.cs b/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/ICommandPredictor.cs index 95e8487bba..1c632c541c 100644 --- a/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/ICommandPredictor.cs +++ b/src/System.Management.Automation/engine/Subsystem/PredictionSubsystem/ICommandPredictor.cs @@ -201,7 +201,7 @@ namespace System.Management.Automation.Subsystem.Prediction /// A object. public static PredictionContext Create(string input) { - Requires.NotNullOrEmpty(input, nameof(input)); + ArgumentException.ThrowIfNullOrEmpty(input); Ast ast = Parser.ParseInput(input, out Token[] tokens, out _); return new PredictionContext(ast, tokens); @@ -239,7 +239,7 @@ namespace System.Management.Automation.Subsystem.Prediction /// The tooltip of the suggestion. public PredictiveSuggestion(string suggestion, string? toolTip) { - Requires.NotNullOrEmpty(suggestion, nameof(suggestion)); + ArgumentException.ThrowIfNullOrEmpty(suggestion); SuggestionText = suggestion; ToolTip = toolTip; diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index bb0a50e8bc..a6642e81c5 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -1733,14 +1733,6 @@ namespace System.Management.Automation.Internal /// internal static class Requires { - internal static void NotNullOrEmpty(string value, string paramName) - { - if (string.IsNullOrEmpty(value)) - { - throw new ArgumentNullException(paramName); - } - } - internal static void NotNullOrEmpty(ICollection value, string paramName) { if (value is null || value.Count == 0)