From ebda1090fd471e607bacc5a54fe816c78619394e Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 18 May 2020 19:49:56 +0100 Subject: [PATCH] Use nameof operator Fix RCS1015 --- .../cmdletization/SessionBasedWrapper.cs | 6 +- .../cmdletization/cim/CimJobException.cs | 4 +- .../cmdletization/cim/cimConverter.cs | 6 +- .../cimSupport/cmdletization/cim/cimQuery.cs | 4 +- .../cmdletization/cim/cimWrapper.cs | 2 +- .../commands/management/CIMHelper.cs | 4 +- .../commands/management/Computer.cs | 4 +- .../commands/management/ContentCommandBase.cs | 4 +- .../commands/management/Process.cs | 2 +- .../commands/management/Service.cs | 6 +- .../commands/management/SetContentCommand.cs | 2 +- .../commands/utility/AddType.cs | 2 +- .../commands/utility/CustomSerialization.cs | 4 +- .../EnableDisableRunspaceDebugCommand.cs | 2 +- .../OutGridView/OutWindowProxy.cs | 10 +- .../commands/utility/GetRandomCommand.cs | 4 +- .../utility/ImplicitRemotingCommands.cs | 68 ++++---- .../commands/utility/Select-Object.cs | 2 +- .../ShowCommand/ShowCommandCommandInfo.cs | 4 +- .../ShowCommand/ShowCommandModuleInfo.cs | 4 +- .../ShowCommand/ShowCommandParameterInfo.cs | 4 +- .../ShowCommandParameterSetInfo.cs | 4 +- .../ShowCommand/ShowCommandParameterType.cs | 4 +- .../commands/utility/UtilityCommon.cs | 6 +- .../Common/InvokeRestMethodCommand.Common.cs | 4 +- .../Common/WebRequestPSCmdlet.Common.cs | 30 ++-- .../Common/WebResponseObject.Common.cs | 2 +- .../InvokeWebRequestCommand.CoreClr.cs | 2 +- .../utility/WebCmdlet/CoreCLR/WebProxy.cs | 4 +- .../utility/trace/MshHostTraceListener.cs | 2 +- .../utility/trace/TraceExpressionCommand.cs | 4 +- .../WindowsTaskbarJumpList/PropVariant.cs | 2 +- .../host/msh/ConsoleControl.cs | 2 +- .../host/msh/ConsoleHost.cs | 2 +- .../host/msh/ConsoleHostRawUserInterface.cs | 24 +-- .../msh/ConsoleHostUserInterfacePrompt.cs | 6 +- ...ConsoleHostUserInterfacePromptForChoice.cs | 10 +- .../host/msh/ProgressPane.cs | 2 +- .../DotNetCode/Eventing/EventDescriptor.cs | 8 +- .../DotNetCode/Eventing/EventProvider.cs | 6 +- .../Eventing/EventProviderTraceListener.cs | 2 +- .../VT100EscapeSequences.cs | 2 +- .../security/AclCommands.cs | 22 +-- .../security/CertificateProvider.cs | 6 +- .../security/SignatureCommands.cs | 2 +- .../CurrentConfigurations.cs | 18 +-- src/Microsoft.WSMan.Management/WsManHelper.cs | 6 +- .../CoreCLR/CorePsAssemblyLoadContext.cs | 4 +- .../DscSupport/CimDSCParser.cs | 22 +-- .../FormatAndOutput/common/BaseCommand.cs | 2 +- .../common/BaseFormattingCommandParameters.cs | 4 +- .../common/BaseOutputtingCommand.cs | 2 +- .../common/DisplayDatabase/FormatTable.cs | 10 +- .../DisplayDatabase/displayDescriptionData.cs | 20 +-- .../displayDescriptionData_Complex.cs | 4 +- .../displayDescriptionData_List.cs | 8 +- .../displayDescriptionData_Table.cs | 8 +- .../displayDescriptionData_Wide.cs | 10 +- .../common/DisplayDatabase/typeDataManager.cs | 4 +- .../DisplayDatabase/typeDataXmlLoader.cs | 20 +-- .../typeDataXmlLoader_Views.cs | 4 +- .../common/FormatViewGenerator_Complex.cs | 4 +- .../common/FormattingObjectsDeserializer.cs | 12 +- .../FormatAndOutput/common/ILineOutput.cs | 6 +- .../common/Utilities/MshParameter.cs | 2 +- .../Utilities/MshParameterAssociation.cs | 2 +- .../common/Utilities/Mshexpression.cs | 4 +- .../out-console/ConsoleLineOutput.cs | 6 +- .../cmdletization/MethodInvocationInfo.cs | 4 +- .../cmdletization/ObjectModelWrapper.cs | 8 +- .../other/ciminstancetypeadapter.cs | 14 +- .../engine/ApplicationInfo.cs | 4 +- .../ChildrenCmdletProviderInterfaces.cs | 4 +- .../engine/CmdletFamilyProviderInterfaces.cs | 4 +- .../engine/CmdletInfo.cs | 10 +- .../engine/CmdletParameterBinderController.cs | 20 +-- .../engine/CodeMethods.cs | 4 +- .../engine/CommandBase.cs | 2 +- .../CommandCompletion/CommandCompletion.cs | 32 ++-- .../CommandCompletion/CompletionCompleters.cs | 2 +- .../CommandCompletion/CompletionResult.cs | 8 +- .../CommandCompletion/ExtensibleCompletion.cs | 8 +- .../PseudoParameterBinder.cs | 22 +-- .../engine/CommandDiscovery.cs | 8 +- .../engine/CommandInfo.cs | 8 +- .../engine/CommandMetadata.cs | 12 +- .../engine/CommandProcessor.cs | 2 +- .../engine/CommandProcessorBase.cs | 6 +- .../engine/CommonCommandParameters.cs | 2 +- .../engine/CompiledCommandParameter.cs | 6 +- .../engine/ContentCmdletProviderInterfaces.cs | 4 +- .../engine/CoreAdapter.cs | 4 +- .../engine/Credential.cs | 2 +- .../engine/DataStoreAdapter.cs | 18 +-- .../engine/DataStoreAdapterProvider.cs | 8 +- .../engine/DefaultCommandRuntime.cs | 2 +- .../engine/DriveInterfaces.cs | 2 +- .../engine/EngineIntrinsics.cs | 2 +- .../engine/ErrorPackage.cs | 2 +- .../engine/EventManager.cs | 14 +- .../ExperimentalFeature.cs | 2 +- .../engine/ExtendedTypeSystemException.cs | 2 +- .../engine/ExternalScriptInfo.cs | 4 +- .../engine/FunctionInfo.cs | 2 +- .../engine/GetCommandCommand.cs | 2 +- .../engine/ItemCmdletProviderInterfaces.cs | 4 +- .../engine/LanguagePrimitives.cs | 14 +- .../engine/MergedCommandParameterMetadata.cs | 4 +- .../engine/Modules/ModuleCmdletBase.cs | 2 +- .../engine/Modules/PSModuleInfo.cs | 4 +- .../engine/Modules/RemoteDiscoveryHelper.cs | 2 +- .../engine/MshCmdlet.cs | 16 +- .../engine/MshCommandRuntime.cs | 8 +- .../engine/MshMemberInfo.cs | 106 ++++++------- .../engine/MshObject.cs | 10 +- .../engine/MshObjectTypeDescriptor.cs | 6 +- .../engine/NativeCommandProcessor.cs | 2 +- .../engine/PSClassInfo.cs | 2 +- .../engine/ParameterBinderBase.cs | 10 +- .../engine/ParameterBinderController.cs | 2 +- .../engine/ParameterInfo.cs | 2 +- .../engine/ParameterSetInfo.cs | 4 +- .../engine/ParameterSetSpecificMetadata.cs | 2 +- .../engine/PathInterfaces.cs | 2 +- .../engine/ProgressRecord.cs | 12 +- .../PropertyCmdletProviderInterfaces.cs | 4 +- .../engine/ProviderInterfaces.cs | 2 +- .../engine/ProxyCommand.cs | 2 +- .../engine/PseudoParameterBinder.cs | 2 +- .../engine/PseudoParameters.cs | 4 +- .../engine/ScopedItemSearcher.cs | 4 +- .../engine/ScriptInfo.cs | 2 +- ...urityDescriptorCmdletProviderInterfaces.cs | 4 +- .../engine/SessionState.cs | 2 +- .../engine/SessionStateAliasAPIs.cs | 14 +- .../engine/SessionStateCmdletAPIs.cs | 4 +- .../engine/SessionStateContainer.cs | 62 ++++---- .../engine/SessionStateContent.cs | 18 +-- .../engine/SessionStateDriveAPIs.cs | 20 +-- .../engine/SessionStateDynamicProperty.cs | 72 ++++----- .../engine/SessionStateFunctionAPIs.cs | 16 +- .../engine/SessionStateItem.cs | 24 +-- .../engine/SessionStateLocationAPIs.cs | 14 +- .../engine/SessionStateNavigation.cs | 30 ++-- .../engine/SessionStateProperty.cs | 22 +-- .../engine/SessionStateProviderAPIs.cs | 38 ++--- .../engine/SessionStatePublic.cs | 6 +- .../engine/SessionStateScope.cs | 6 +- ...SessionStateSecurityDescriptorInterface.cs | 22 +-- .../engine/SessionStateUtils.cs | 2 +- .../engine/SessionStateVariableAPIs.cs | 32 ++-- .../engine/ShellVariable.cs | 2 +- .../engine/ThirdPartyAdapter.cs | 2 +- .../engine/TypeMetadata.cs | 14 +- .../engine/TypeTable.cs | 34 ++-- .../engine/UserFeedbackParameters.cs | 4 +- .../engine/VariableAttributeCollection.cs | 2 +- .../engine/VariableInterfaces.cs | 2 +- .../engine/VariablePath.cs | 2 +- .../engine/cmdlet.cs | 10 +- .../engine/debugger/debugger.cs | 40 ++--- .../engine/hostifaces/AsyncResult.cs | 2 +- .../engine/hostifaces/ChoiceDescription.cs | 6 +- .../engine/hostifaces/Command.cs | 16 +- .../engine/hostifaces/Connection.cs | 6 +- .../engine/hostifaces/ConnectionBase.cs | 16 +- .../engine/hostifaces/ConnectionFactory.cs | 12 +- .../engine/hostifaces/FieldDescription.cs | 10 +- .../engine/hostifaces/History.cs | 14 +- .../engine/hostifaces/HostUtilities.cs | 4 +- .../hostifaces/InternalHostUserInterface.cs | 14 +- .../engine/hostifaces/ListModifier.cs | 10 +- .../engine/hostifaces/LocalConnection.cs | 2 +- .../engine/hostifaces/LocalPipeline.cs | 2 +- .../hostifaces/MshHostRawUserInterface.cs | 16 +- .../engine/hostifaces/PSCommand.cs | 8 +- .../engine/hostifaces/PSDataCollection.cs | 16 +- .../engine/hostifaces/PSTask.cs | 2 +- .../engine/hostifaces/Parameter.cs | 10 +- .../engine/hostifaces/Pipeline.cs | 2 +- .../engine/hostifaces/PowerShell.cs | 28 ++-- .../engine/hostifaces/RunspacePoolInternal.cs | 30 ++-- .../engine/hostifaces/pipelinebase.cs | 4 +- .../engine/lang/interface/PSParser.cs | 4 +- .../engine/lang/parserutils.cs | 2 +- .../engine/parser/Compiler.cs | 2 +- .../engine/parser/SafeValues.cs | 2 +- .../engine/parser/ast.cs | 150 +++++++++--------- .../engine/parser/tokenizer.cs | 8 +- .../engine/pipeline.cs | 8 +- .../engine/regex.cs | 4 +- .../remoting/client/ClientMethodExecutor.cs | 2 +- .../engine/remoting/client/Job.cs | 12 +- .../engine/remoting/client/Job2.cs | 4 +- .../engine/remoting/client/JobManager.cs | 10 +- .../remoting/client/JobSourceAdapter.cs | 2 +- .../client/RemoteRunspacePoolInternal.cs | 8 +- .../remoting/client/RemotingErrorRecord.cs | 4 +- .../engine/remoting/client/ThrottlingJob.cs | 8 +- .../remoting/client/clientremotesession.cs | 6 +- ...clientremotesessionprotocolstatemachine.cs | 4 +- .../engine/remoting/client/remotepipeline.cs | 2 +- .../engine/remoting/client/remoterunspace.cs | 16 +- .../client/remotingprotocolimplementation.cs | 12 +- .../remoting/commands/InvokeCommandCommand.cs | 2 +- .../remoting/commands/PSRemotingCmdlet.cs | 26 +-- .../remoting/commands/PopRunspaceCommand.cs | 2 +- .../remoting/commands/PushRunspaceCommand.cs | 20 +-- .../remoting/commands/newrunspacecommand.cs | 12 +- .../remoting/commands/remotingcommandutil.cs | 8 +- .../common/RemoteSessionHyperVSocket.cs | 2 +- .../remoting/common/RemoteSessionNamedPipe.cs | 22 +-- .../remoting/common/RunspaceConnectionInfo.cs | 20 +-- .../common/WireDataFormat/EncodeAndDecode.cs | 52 +++--- .../engine/remoting/common/misc.cs | 6 +- .../remoting/common/remotingexceptions.cs | 8 +- .../fanin/InitialSessionStateProvider.cs | 16 +- .../fanin/OutOfProcTransportManager.cs | 22 +-- .../server/OutOfProcServerMediator.cs | 4 +- .../ServerRemoteHostRawUserInterface.cs | 4 +- .../server/ServerRemotingProtocol2.cs | 4 +- .../server/ServerRunspacePoolDriver.cs | 6 +- .../remoting/server/serverremotesession.cs | 8 +- .../server/serverremotesessionstatemachine.cs | 48 +++--- .../serverremotingprotocolimplementation.cs | 2 +- .../engine/runtime/CompiledScriptBlock.cs | 2 +- .../engine/runtime/Operations/MiscOps.cs | 4 +- .../engine/runtime/Operations/StringOps.cs | 2 +- .../engine/serialization.cs | 32 ++-- .../help/CommandHelpProvider.cs | 2 +- .../help/HelpCategoryInvalidException.cs | 2 +- .../help/HelpNotFoundException.cs | 2 +- .../help/ProviderHelpProvider.cs | 2 +- .../logging/MshLog.cs | 34 ++-- .../namespaces/AliasProvider.cs | 2 +- .../namespaces/CoreCommandContext.cs | 14 +- .../namespaces/FileSystemContentStream.cs | 6 +- .../namespaces/FileSystemProvider.cs | 82 +++++----- .../namespaces/FileSystemSecurity.cs | 10 +- .../namespaces/FunctionProvider.cs | 2 +- .../namespaces/LocationGlobber.cs | 2 +- .../namespaces/NavigationProviderBase.cs | 8 +- .../namespaces/ProviderBase.cs | 18 +-- .../ProviderDeclarationAttribute.cs | 4 +- .../namespaces/RegistryProvider.cs | 68 ++++---- .../namespaces/RegistrySecurity.cs | 12 +- .../namespaces/SessionStateProviderBase.cs | 26 +-- .../namespaces/StackInfo.cs | 4 +- .../security/Authenticode.cs | 8 +- .../security/CredentialParameter.cs | 2 +- .../security/SecureStringHelper.cs | 6 +- .../security/SecurityManager.cs | 2 +- .../singleshell/config/MshSnapinInfo.cs | 40 ++--- .../config/MshSnapinLoadException.cs | 2 +- .../utils/CommandDiscoveryExceptions.cs | 8 +- .../utils/ExecutionExceptions.cs | 14 +- .../utils/MshArgumentException.cs | 2 +- .../utils/MshArgumentNullException.cs | 2 +- .../utils/MshArgumentOutOfRangeException.cs | 2 +- .../utils/MshInvalidOperationException.cs | 2 +- .../utils/MshNotImplementedException.cs | 2 +- .../utils/MshNotSupportedException.cs | 2 +- .../utils/MshObjectDisposedException.cs | 2 +- .../utils/MshTraceSource.cs | 28 ++-- .../utils/ObjectReader.cs | 6 +- .../utils/ObjectStream.cs | 8 +- .../utils/ObjectWriter.cs | 2 +- .../utils/ParameterBinderExceptions.cs | 16 +- .../utils/ParserException.cs | 4 +- .../utils/PowerShellExecutionHelper.cs | 2 +- .../utils/PsUtils.cs | 12 +- .../utils/ResourceManagerCache.cs | 12 +- .../utils/RuntimeException.cs | 2 +- .../utils/SessionStateExceptions.cs | 4 +- .../utils/StructuredTraceSource.cs | 2 +- .../utils/tracing/EtwActivity.cs | 24 +-- .../EtwActivityReverterMethodInvoker.cs | 2 +- .../utils/tracing/EtwEventCorrelator.cs | 2 +- 278 files changed, 1429 insertions(+), 1429 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs index 0c03623110b..9ad44f3a07f 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs @@ -581,8 +581,8 @@ private TSession GetImpliedSession() /// true if successful method invocations should emit downstream the being operated on. public override void ProcessRecord(TObjectInstance objectInstance, MethodInvocationInfo methodInvocationInfo, bool passThru) { - if (objectInstance == null) throw new ArgumentNullException("objectInstance"); - if (methodInvocationInfo == null) throw new ArgumentNullException("methodInvocationInfo"); + if (objectInstance == null) throw new ArgumentNullException(nameof(objectInstance)); + if (methodInvocationInfo == null) throw new ArgumentNullException(nameof(methodInvocationInfo)); foreach (TSession sessionForJob in this.GetSessionsToActAgainst(objectInstance)) { @@ -607,7 +607,7 @@ public override void ProcessRecord(TObjectInstance objectInstance, MethodInvocat /// Method invocation details. public override void ProcessRecord(MethodInvocationInfo methodInvocationInfo) { - if (methodInvocationInfo == null) throw new ArgumentNullException("methodInvocationInfo"); + if (methodInvocationInfo == null) throw new ArgumentNullException(nameof(methodInvocationInfo)); foreach (TSession sessionForJob in this.GetSessionsToActAgainst(methodInvocationInfo)) { diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/CimJobException.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/CimJobException.cs index b9a1d210823..092103d6fe7 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/CimJobException.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/CimJobException.cs @@ -56,7 +56,7 @@ protected CimJobException( { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } _errorRecord = (ErrorRecord)info.GetValue("errorRecord", typeof(ErrorRecord)); @@ -71,7 +71,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimConverter.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimConverter.cs index 58a9f02338b..033b8813534 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimConverter.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimConverter.cs @@ -52,12 +52,12 @@ private unsafe void Copy(char* source, int offset, int charsToCopy) { if ((offset < 0) || (offset >= _string.Length)) { - throw new ArgumentOutOfRangeException("offset"); + throw new ArgumentOutOfRangeException(nameof(offset)); } if (offset + charsToCopy > _string.Length) { - throw new ArgumentOutOfRangeException("charsToCopy"); + throw new ArgumentOutOfRangeException(nameof(charsToCopy)); } fixed (char* target = _string) @@ -352,7 +352,7 @@ internal static object ConvertFromDotNetToCim(object dotNetObject) /// The only kind of exception this method can throw. internal static object ConvertFromCimToDotNet(object cimObject, Type expectedDotNetType) { - if (expectedDotNetType == null) { throw new ArgumentNullException("expectedDotNetType"); } + if (expectedDotNetType == null) { throw new ArgumentNullException(nameof(expectedDotNetType)); } if (cimObject == null) { diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs index ba727baaef4..551b2149e41 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs @@ -316,12 +316,12 @@ public override void AddQueryOption(string optionName, object optionValue) { if (string.IsNullOrEmpty(optionName)) { - throw new ArgumentNullException("optionName"); + throw new ArgumentNullException(nameof(optionName)); } if (optionValue == null) { - throw new ArgumentNullException("optionValue"); + throw new ArgumentNullException(nameof(optionValue)); } this.queryOptions[optionName] = optionValue; diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs index acd432037fb..d78c8d631e9 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimWrapper.cs @@ -175,7 +175,7 @@ internal override StartableJob CreateQueryJob(CimSession session, QueryBuilder b CimQuery query = baseQuery as CimQuery; if (query == null) { - throw new ArgumentNullException("baseQuery"); + throw new ArgumentNullException(nameof(baseQuery)); } TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.CmdletInvocationInfo, isStaticCmdlet: false); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs index edf1249638f..559af13127b 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs @@ -80,7 +80,7 @@ internal static string WqlQueryAll(string from) internal static T GetFirst(CimSession session, string nameSpace, string wmiClassName) where T : class, new() { if (string.IsNullOrEmpty(wmiClassName)) - throw new ArgumentException("String argument may not be null or empty", "wmiClassName"); + throw new ArgumentException("String argument may not be null or empty", nameof(wmiClassName)); try { @@ -133,7 +133,7 @@ internal static string WqlQueryAll(string from) internal static T[] GetAll(CimSession session, string nameSpace, string wmiClassName) where T : class, new() { if (string.IsNullOrEmpty(wmiClassName)) - throw new ArgumentException("String argument may not be null or empty", "wmiClassName"); + throw new ArgumentException("String argument may not be null or empty", nameof(wmiClassName)); var rv = new List(); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs index 578b4a7efde..ece9d77e511 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs @@ -107,7 +107,7 @@ private RestartComputerTimeoutException(SerializationInfo info, StreamingContext { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } ComputerName = info.GetString("ComputerName"); @@ -128,7 +128,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs index 34f7636174d..2271388c096 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs @@ -348,7 +348,7 @@ internal ContentHolder( { if (pathInfo == null) { - throw PSTraceSource.NewArgumentNullException("pathInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(pathInfo)); } PathInfo = pathInfo; @@ -370,7 +370,7 @@ internal void CloseContent(List contentHolders, bool disposing) { if (contentHolders == null) { - throw PSTraceSource.NewArgumentNullException("contentHolders"); + throw PSTraceSource.NewArgumentNullException(nameof(contentHolders)); } foreach (ContentHolder holder in contentHolders) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 2ba50c23459..b17dfa02058 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -3005,7 +3005,7 @@ public override void GetObjectData( base.GetObjectData(info, context); if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); info.AddValue("ProcessName", _processName); } diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs index 8081e98c261..f62591fa19c 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs @@ -547,7 +547,7 @@ private void IncludeExcludeAdd( private bool Matches(ServiceController service, string[] matchList) { if (matchList == null) - throw PSTraceSource.NewArgumentNullException("matchList"); + throw PSTraceSource.NewArgumentNullException(nameof(matchList)); string serviceID = (selectionMode == SelectionMode.DisplayName) ? service.DisplayName : service.ServiceName; @@ -2566,7 +2566,7 @@ protected ServiceCommandException(SerializationInfo info, StreamingContext conte { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } _serviceName = info.GetString("ServiceName"); @@ -2581,7 +2581,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs index b73edc3f291..4e040517b02 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs @@ -28,7 +28,7 @@ internal override void BeforeOpenStreams(string[] paths) { if (paths == null || paths.Length == 0) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(GetCurrentContext()); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index 833c373ca9c..2e733802fa2 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -887,7 +887,7 @@ private OutputKind OutputAssemblyTypeToOutputKind(OutputAssemblyType outputType) case OutputAssemblyType.WindowsApplication: return OutputKind.WindowsApplication; default: - throw new ArgumentOutOfRangeException("outputType"); + throw new ArgumentOutOfRangeException(nameof(outputType)); } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs index 91985bd17c7..22572c65443 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CustomSerialization.cs @@ -55,12 +55,12 @@ internal CustomSerialization(XmlWriter writer, bool notypeinformation, int depth { if (writer == null) { - throw PSTraceSource.NewArgumentException("writer"); + throw PSTraceSource.NewArgumentException(nameof(writer)); } if (depth < 1) { - throw PSTraceSource.NewArgumentException("writer", Serialization.DepthOfOneRequired); + throw PSTraceSource.NewArgumentException(nameof(writer), Serialization.DepthOfOneRequired); } _depth = depth; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/EnableDisableRunspaceDebugCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/EnableDisableRunspaceDebugCommand.cs index 6896917429f..c1294a08535 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/EnableDisableRunspaceDebugCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/EnableDisableRunspaceDebugCommand.cs @@ -75,7 +75,7 @@ public int RunspaceId /// Runspace local Id. public PSRunspaceDebug(bool enabled, bool breakAll, string runspaceName, int runspaceId) { - if (string.IsNullOrEmpty(runspaceName)) { throw new PSArgumentNullException("runspaceName"); } + if (string.IsNullOrEmpty(runspaceName)) { throw new PSArgumentNullException(nameof(runspaceName)); } this.Enabled = enabled; this.BreakAll = breakAll; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs index 49d41d8ce3e..871b1a1bb62 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutWindowProxy.cs @@ -59,17 +59,17 @@ internal void AddColumns(string[] propertyNames, string[] displayNames, Type[] t { if (propertyNames == null) { - throw new ArgumentNullException("propertyNames"); + throw new ArgumentNullException(nameof(propertyNames)); } if (displayNames == null) { - throw new ArgumentNullException("displayNames"); + throw new ArgumentNullException(nameof(displayNames)); } if (types == null) { - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); } try @@ -178,7 +178,7 @@ internal void AddItem(PSObject livePSObject) { if (livePSObject == null) { - throw new ArgumentNullException("livePSObject"); + throw new ArgumentNullException(nameof(livePSObject)); } if (_headerInfo == null) @@ -204,7 +204,7 @@ internal void AddHeteroViewItem(PSObject livePSObject) { if (livePSObject == null) { - throw new ArgumentNullException("livePSObject"); + throw new ArgumentNullException(nameof(livePSObject)); } if (_headerInfo == null) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs index 91955c0f26c..6e4445ba28e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs @@ -644,7 +644,7 @@ internal int Next(int maxValue) { if (maxValue < 0) { - throw new ArgumentOutOfRangeException("maxValue", GetRandomCommandStrings.MaxMustBeGreaterThanZeroApi); + throw new ArgumentOutOfRangeException(nameof(maxValue), GetRandomCommandStrings.MaxMustBeGreaterThanZeroApi); } return Next(0, maxValue); @@ -660,7 +660,7 @@ public int Next(int minValue, int maxValue) { if (minValue > maxValue) { - throw new ArgumentOutOfRangeException("minValue", GetRandomCommandStrings.MinGreaterThanOrEqualMaxApi); + throw new ArgumentOutOfRangeException(nameof(minValue), GetRandomCommandStrings.MinGreaterThanOrEqualMaxApi); } int randomNumber = 0; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs index 61b71fe8f45..a1bc3762fcb 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs @@ -187,7 +187,7 @@ private void RegisterModuleCleanUp(PSModuleInfo moduleInfo) { if (moduleInfo == null) { - throw PSTraceSource.NewArgumentNullException("moduleInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(moduleInfo)); } // Note: we are using this.Context.Events to make sure that the event handler @@ -534,7 +534,7 @@ internal ErrorDetails GetErrorDetails(string errorId, params object[] args) { if (string.IsNullOrEmpty(errorId)) { - throw PSTraceSource.NewArgumentNullException("errorId"); + throw PSTraceSource.NewArgumentNullException(nameof(errorId)); } return new ErrorDetails( @@ -564,7 +564,7 @@ private ErrorRecord GetErrorMalformedDataFromRemoteCommand(string commandName) { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentNullException("commandName"); + throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } string errorId = "ErrorMalformedDataFromRemoteCommand"; @@ -585,7 +585,7 @@ private ErrorRecord GetErrorCommandSkippedBecauseOfShadowing(string commandNames { if (string.IsNullOrEmpty(commandNames)) { - throw PSTraceSource.NewArgumentNullException("commandNames"); + throw PSTraceSource.NewArgumentNullException(nameof(commandNames)); } string errorId = "ErrorCommandSkippedBecauseOfShadowing"; @@ -606,7 +606,7 @@ private ErrorRecord GetErrorSkippedNonRequestedCommand(string commandName) { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentNullException("commandName"); + throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } string errorId = "ErrorSkippedNonRequestedCommand"; @@ -627,7 +627,7 @@ private ErrorRecord GetErrorSkippedNonRequestedTypeDefinition(string typeName) { if (string.IsNullOrEmpty(typeName)) { - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); } string errorId = "ErrorSkippedNonRequestedTypeDefinition"; @@ -648,7 +648,7 @@ private ErrorRecord GetErrorSkippedUnsafeCommandName(string commandName) { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentNullException("commandName"); + throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } string errorId = "ErrorSkippedUnsafeCommandName"; @@ -669,18 +669,18 @@ private ErrorRecord GetErrorSkippedUnsafeNameInMetadata(string commandName, stri { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentNullException("commandName"); + throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } if (string.IsNullOrEmpty(nameType)) { - throw PSTraceSource.NewArgumentNullException("nameType"); + throw PSTraceSource.NewArgumentNullException(nameof(nameType)); } Dbg.Assert(nameType.Equals("Alias") || nameType.Equals("ParameterSet") || nameType.Equals("Parameter"), "nameType matches resource names"); if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } string errorId = "ErrorSkippedUnsafe" + nameType + "Name"; @@ -701,12 +701,12 @@ private ErrorRecord GetErrorFromRemoteCommand(string commandName, RuntimeExcepti { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentNullException("commandName"); + throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } if (runtimeException == null) { - throw PSTraceSource.NewArgumentNullException("runtimeException"); + throw PSTraceSource.NewArgumentNullException(nameof(runtimeException)); } string errorId; @@ -755,7 +755,7 @@ private ErrorRecord GetErrorCouldntResolvedAlias(string aliasName) { if (string.IsNullOrEmpty(aliasName)) { - throw PSTraceSource.NewArgumentNullException("aliasName"); + throw PSTraceSource.NewArgumentNullException(nameof(aliasName)); } string errorId = "ErrorCouldntResolveAlias"; @@ -776,7 +776,7 @@ private ErrorRecord GetErrorNoResultsFromRemoteEnd(string commandName) { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentNullException("commandName"); + throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } string errorId = "ErrorNoResultsFromRemoteEnd"; @@ -872,7 +872,7 @@ private bool IsCommandNameAllowedForImport(string commandName) { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentNullException("commandName"); + throw PSTraceSource.NewArgumentNullException(nameof(commandName)); } if (this.AllowClobber.IsPresent) @@ -1270,7 +1270,7 @@ private ParameterMetadata RehydrateParameterMetadata(PSObject deserializedParame { if (deserializedParameterMetadata == null) { - throw PSTraceSource.NewArgumentNullException("deserializedParameterMetadata"); + throw PSTraceSource.NewArgumentNullException(nameof(deserializedParameterMetadata)); } string name = GetPropertyValue("Get-Command", deserializedParameterMetadata, "Name"); @@ -1311,7 +1311,7 @@ private CommandMetadata RehydrateCommandMetadata(PSObject deserializedCommandInf { if (deserializedCommandInfo == null) { - throw PSTraceSource.NewArgumentNullException("deserializedCommandInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(deserializedCommandInfo)); } string name = GetPropertyValue("Get-Command", deserializedCommandInfo, "Name"); @@ -1964,7 +1964,7 @@ private string EscapeFunctionNameForRemoteHelp(string name) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } StringBuilder result = new StringBuilder(name.Length); @@ -2014,7 +2014,7 @@ private void GenerateManifest(TextWriter writer, string psm1fileName, string for { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } GenerateTopComment(writer); @@ -2087,7 +2087,7 @@ private void GenerateModuleHeader(TextWriter writer) { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } // In Win8, we are no longer loading all assemblies by default. @@ -2123,7 +2123,7 @@ private void GenerateHelperFunctionsWriteMessage(TextWriter writer) { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } writer.Write(HelperFunctionsWriteMessage); @@ -2177,7 +2177,7 @@ private void GenerateHelperFunctionsSetImplicitRunspace(TextWriter writer) { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } string runspaceNameTemplate = StringUtil.Format(ImplicitRemotingStrings.ProxyRunspaceNameTemplate); @@ -2208,7 +2208,7 @@ private void GenerateHelperFunctionsGetSessionOption(TextWriter writer) { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } writer.Write( @@ -2403,7 +2403,7 @@ private void GenerateHelperFunctionsGetImplicitRunspace(TextWriter writer) { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } string hashString; @@ -2752,7 +2752,7 @@ private void GenerateHelperFunctionsClientSideParameters(TextWriter writer) { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } writer.Write(HelperFunctionsModifyParameters); @@ -2831,7 +2831,7 @@ private void GenerateCommandProxy(TextWriter writer, CommandMetadata commandMeta { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } string functionNameForString = CodeGeneration.EscapeSingleQuotedStringContent(commandMetadata.Name); @@ -2853,12 +2853,12 @@ private void GenerateCommandProxy(TextWriter writer, IEnumerable GetListOfCommandNames(IEnumerable listOfCo { if (listOfCommandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("listOfCommandMetadata"); + throw PSTraceSource.NewArgumentNullException(nameof(listOfCommandMetadata)); } List listOfCommandNames = new List(); @@ -2915,7 +2915,7 @@ private string GenerateArrayString(IEnumerable listOfStrings) { if (listOfStrings == null) { - throw PSTraceSource.NewArgumentNullException("listOfStrings"); + throw PSTraceSource.NewArgumentNullException(nameof(listOfStrings)); } StringBuilder arrayString = new StringBuilder(); @@ -2976,12 +2976,12 @@ private void GenerateFormatFile(TextWriter writer, List { if (writer == null) { - throw PSTraceSource.NewArgumentNullException("writer"); + throw PSTraceSource.NewArgumentNullException(nameof(writer)); } if (listOfFormatData == null) { - throw PSTraceSource.NewArgumentNullException("listOfFormatData"); + throw PSTraceSource.NewArgumentNullException(nameof(listOfFormatData)); } XmlWriterSettings settings = new XmlWriterSettings(); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs index e5405172bee..7614278b602 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs @@ -25,7 +25,7 @@ internal PSPropertyExpressionFilter(string[] wildcardPatternsStrings) { if (wildcardPatternsStrings == null) { - throw new ArgumentNullException("wildcardPatternsStrings"); + throw new ArgumentNullException(nameof(wildcardPatternsStrings)); } _wildcardPatterns = new WildcardPattern[wildcardPatternsStrings.Length]; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandCommandInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandCommandInfo.cs index 115920651a4..c0226471bdd 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandCommandInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandCommandInfo.cs @@ -23,7 +23,7 @@ public ShowCommandCommandInfo(CommandInfo other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Name; @@ -71,7 +71,7 @@ public ShowCommandCommandInfo(PSObject other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Members["Name"].Value as string; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandModuleInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandModuleInfo.cs index 9111cd88216..457cf6d7028 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandModuleInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandModuleInfo.cs @@ -21,7 +21,7 @@ public ShowCommandModuleInfo(PSModuleInfo other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Name; @@ -37,7 +37,7 @@ public ShowCommandModuleInfo(PSObject other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Members["Name"].Value as string; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterInfo.cs index 6e4732f7eac..665fa039929 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterInfo.cs @@ -23,7 +23,7 @@ public ShowCommandParameterInfo(CommandParameterInfo other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Name; @@ -50,7 +50,7 @@ public ShowCommandParameterInfo(PSObject other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Members["Name"].Value as string; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterSetInfo.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterSetInfo.cs index ff63ee13e76..e3c4cbf2cb7 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterSetInfo.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterSetInfo.cs @@ -23,7 +23,7 @@ public ShowCommandParameterSetInfo(CommandParameterSetInfo other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Name; @@ -41,7 +41,7 @@ public ShowCommandParameterSetInfo(PSObject other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.Name = other.Members["Name"].Value as string; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterType.cs index f53d72ea868..d7a3258d27b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommandParameterType.cs @@ -22,7 +22,7 @@ public ShowCommandParameterType(Type other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.FullName = other.FullName; @@ -51,7 +51,7 @@ public ShowCommandParameterType(PSObject other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } this.IsEnum = (bool)(other.Members["IsEnum"].Value); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs index e4ef04b961a..1e404991bc9 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs @@ -121,7 +121,7 @@ public ByteCollection(ulong offset, byte[] value, string path) { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } Offset64 = offset; @@ -150,7 +150,7 @@ public ByteCollection(ulong offset, byte[] value) { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } Offset64 = offset; @@ -179,7 +179,7 @@ public ByteCollection(byte[] value) { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } Bytes = value; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs index fc0921d3c63..273fae835c3 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs @@ -380,7 +380,7 @@ public partial class InvokeRestMethodCommand : WebRequestPSCmdlet /// internal override void ProcessResponse(HttpResponseMessage response) { - if (response == null) { throw new ArgumentNullException("response"); } + if (response == null) { throw new ArgumentNullException(nameof(response)); } var baseResponseStream = StreamHelper.GetResponseStream(response); @@ -480,7 +480,7 @@ internal override void ProcessResponse(HttpResponseMessage response) private RestReturnType CheckReturnType(HttpResponseMessage response) { - if (response == null) { throw new ArgumentNullException("response"); } + if (response == null) { throw new ArgumentNullException(nameof(response)); } RestReturnType rt = RestReturnType.Detect; string contentType = ContentHelper.GetContentType(response); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index ee56360e103..801660c0e8e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -751,7 +751,7 @@ private Uri PrepareUri(Uri uri) private Uri CheckProtocol(Uri uri) { - if (uri == null) { throw new ArgumentNullException("uri"); } + if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (!uri.IsAbsoluteUri) { @@ -770,7 +770,7 @@ private string QualifyFilePath(string path) private string FormatDictionary(IDictionary content) { if (content == null) - throw new ArgumentNullException("content"); + throw new ArgumentNullException(nameof(content)); StringBuilder bodyBuilder = new StringBuilder(); foreach (string key in content.Keys) @@ -1165,7 +1165,7 @@ internal virtual HttpRequestMessage GetRequest(Uri uri) internal virtual void FillRequestStream(HttpRequestMessage request) { - if (request == null) { throw new ArgumentNullException("request"); } + if (request == null) { throw new ArgumentNullException(nameof(request)); } // set the content type if (ContentType != null) @@ -1338,9 +1338,9 @@ private bool ShouldRetry(HttpStatusCode code) internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestMessage request, bool keepAuthorization) { - if (client == null) { throw new ArgumentNullException("client"); } + if (client == null) { throw new ArgumentNullException(nameof(client)); } - if (request == null) { throw new ArgumentNullException("request"); } + if (request == null) { throw new ArgumentNullException(nameof(request)); } // Add 1 to account for the first request. int totalRequests = WebSession.MaximumRetryCount + 1; @@ -1452,7 +1452,7 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM internal virtual void UpdateSession(HttpResponseMessage response) { - if (response == null) { throw new ArgumentNullException("response"); } + if (response == null) { throw new ArgumentNullException(nameof(response)); } } #endregion Virtual Methods @@ -1658,7 +1658,7 @@ protected override void StopProcessing() internal long SetRequestContent(HttpRequestMessage request, byte[] content) { if (request == null) - throw new ArgumentNullException("request"); + throw new ArgumentNullException(nameof(request)); if (content == null) return 0; @@ -1681,7 +1681,7 @@ internal long SetRequestContent(HttpRequestMessage request, byte[] content) internal long SetRequestContent(HttpRequestMessage request, string content) { if (request == null) - throw new ArgumentNullException("request"); + throw new ArgumentNullException(nameof(request)); if (content == null) return 0; @@ -1730,7 +1730,7 @@ internal long SetRequestContent(HttpRequestMessage request, string content) internal long SetRequestContent(HttpRequestMessage request, XmlNode xmlNode) { if (request == null) - throw new ArgumentNullException("request"); + throw new ArgumentNullException(nameof(request)); if (xmlNode == null) return 0; @@ -1767,9 +1767,9 @@ internal long SetRequestContent(HttpRequestMessage request, XmlNode xmlNode) internal long SetRequestContent(HttpRequestMessage request, Stream contentStream) { if (request == null) - throw new ArgumentNullException("request"); + throw new ArgumentNullException(nameof(request)); if (contentStream == null) - throw new ArgumentNullException("contentStream"); + throw new ArgumentNullException(nameof(contentStream)); var streamContent = new StreamContent(contentStream); request.Content = streamContent; @@ -1791,12 +1791,12 @@ internal long SetRequestContent(HttpRequestMessage request, MultipartFormDataCon { if (request == null) { - throw new ArgumentNullException("request"); + throw new ArgumentNullException(nameof(request)); } if (multipartContent == null) { - throw new ArgumentNullException("multipartContent"); + throw new ArgumentNullException(nameof(multipartContent)); } request.Content = multipartContent; @@ -1807,9 +1807,9 @@ internal long SetRequestContent(HttpRequestMessage request, MultipartFormDataCon internal long SetRequestContent(HttpRequestMessage request, IDictionary content) { if (request == null) - throw new ArgumentNullException("request"); + throw new ArgumentNullException(nameof(request)); if (content == null) - throw new ArgumentNullException("content"); + throw new ArgumentNullException(nameof(content)); string body = FormatDictionary(content); return (SetRequestContent(request, body)); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs index 40e1ddffab0..70c5721dbc1 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs @@ -182,7 +182,7 @@ private void InitializeRawContent(HttpResponseMessage baseResponse) private void SetResponse(HttpResponseMessage response, Stream contentStream) { - if (response == null) { throw new ArgumentNullException("response"); } + if (response == null) { throw new ArgumentNullException(nameof(response)); } BaseResponse = response; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs index 27cca48377c..b0f849490cd 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs @@ -31,7 +31,7 @@ public InvokeWebRequestCommand() : base() /// internal override void ProcessResponse(HttpResponseMessage response) { - if (response == null) { throw new ArgumentNullException("response"); } + if (response == null) { throw new ArgumentNullException(nameof(response)); } Stream responseStream = StreamHelper.GetResponseStream(response); if (ShouldWriteToPipeline) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs index c1df3aa0bf5..5cb4f2b4fde 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebProxy.cs @@ -15,7 +15,7 @@ internal WebProxy(Uri address) { if (address == null) { - throw new ArgumentNullException("address"); + throw new ArgumentNullException(nameof(address)); } _proxyAddress = address; @@ -50,7 +50,7 @@ public Uri GetProxy(Uri destination) { if (destination == null) { - throw new ArgumentNullException("destination"); + throw new ArgumentNullException(nameof(destination)); } if (destination.IsLoopback) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs index fc91cec91c0..9b225bdc141 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/MshHostTraceListener.cs @@ -31,7 +31,7 @@ internal PSHostTraceListener(PSCmdlet cmdlet) { if (cmdlet == null) { - throw new PSArgumentNullException("cmdlet"); + throw new PSArgumentNullException(nameof(cmdlet)); } Diagnostics.Assert( diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs index c7668903ed4..12f8e5b4e09 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs @@ -334,12 +334,12 @@ internal TracePipelineWriter( { if (cmdlet == null) { - throw new ArgumentNullException("cmdlet"); + throw new ArgumentNullException(nameof(cmdlet)); } if (matchingSources == null) { - throw new ArgumentNullException("matchingSources"); + throw new ArgumentNullException(nameof(matchingSources)); } _cmdlet = cmdlet; diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs index 3b9d73c0f4f..b877ab4e384 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropVariant.cs @@ -31,7 +31,7 @@ internal PropVariant(string value) { if (value == null) { - throw new ArgumentException("PropVariantNullString", "value"); + throw new ArgumentException("PropVariantNullString", nameof(value)); } #pragma warning disable CS0618 // Type or member is obsolete (might get deprecated in future versions diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs index 8d3eb856bd0..2229dbb63f1 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs @@ -1084,7 +1084,7 @@ internal static void WriteConsoleOutput(ConsoleHandle consoleHandle, Coordinates Dbg.Assert(!consoleHandle.IsClosed, "ConsoleHandle is closed"); if (contents == null) { - throw PSTraceSource.NewArgumentNullException("contents"); + throw PSTraceSource.NewArgumentNullException(nameof(contents)); } uint codePage; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 43b3a866096..44ad59579d2 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -735,7 +735,7 @@ public class ConsoleColorProxy public ConsoleColorProxy(ConsoleHostUserInterface ui) { - if (ui == null) throw new ArgumentNullException("ui"); + if (ui == null) throw new ArgumentNullException(nameof(ui)); _ui = ui; } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index c1487dead65..91aceef2fbd 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -609,7 +609,7 @@ public override { if ((options & (ReadKeyOptions.IncludeKeyDown | ReadKeyOptions.IncludeKeyUp)) == 0) { - throw PSTraceSource.NewArgumentException("options", ConsoleHostRawUserInterfaceStrings.InvalidReadKeyOptionsError); + throw PSTraceSource.NewArgumentException(nameof(options), ConsoleHostRawUserInterfaceStrings.InvalidReadKeyOptionsError); } // keyInfo is initialized in the below if-else statement @@ -880,14 +880,14 @@ public override { if (contents == null) { - PSTraceSource.NewArgumentNullException("contents"); + PSTraceSource.NewArgumentNullException(nameof(contents)); } // the origin must be within the window. ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO bufferInfo; ConsoleHandle handle = GetBufferInfo(out bufferInfo); - CheckCoordinateWithinBuffer(ref origin, ref bufferInfo, "origin"); + CheckCoordinateWithinBuffer(ref origin, ref bufferInfo, nameof(origin)); // The output is clipped by the console subsystem, so we don't have to check that the array exceeds the buffer // boundaries. @@ -931,14 +931,14 @@ public override // make sure the rect is valid if (region.Right < region.Left) { - throw PSTraceSource.NewArgumentException("region", + throw PSTraceSource.NewArgumentException(nameof(region), ConsoleHostRawUserInterfaceStrings.InvalidRegionErrorTemplate, "region.Right", "region.Left"); } if (region.Bottom < region.Top) { - throw PSTraceSource.NewArgumentException("region", + throw PSTraceSource.NewArgumentException(nameof(region), ConsoleHostRawUserInterfaceStrings.InvalidRegionErrorTemplate, "region.Bottom", "region.Top"); } @@ -960,7 +960,7 @@ public override ConsoleControl.IsCJKOutputCodePage(out codePage) && LengthInBufferCells(fill.Character) == 2) { - throw PSTraceSource.NewArgumentException("fill"); + throw PSTraceSource.NewArgumentException(nameof(fill)); } int cells = bufferWidth * bufferHeight; @@ -1005,7 +1005,7 @@ public override { if (leftExisting[r, 0].BufferCellType == BufferCellType.Leading) { - throw PSTraceSource.NewArgumentException("fill"); + throw PSTraceSource.NewArgumentException(nameof(fill)); } } } @@ -1014,7 +1014,7 @@ public override { if (charLength == 2) { - throw PSTraceSource.NewArgumentException("fill"); + throw PSTraceSource.NewArgumentException(nameof(fill)); } } else @@ -1030,7 +1030,7 @@ public override { if (rightExisting[r, 0].BufferCellType == BufferCellType.Leading) { - throw PSTraceSource.NewArgumentException("fill"); + throw PSTraceSource.NewArgumentException(nameof(fill)); } } } @@ -1040,7 +1040,7 @@ public override { if (rightExisting[r, 0].BufferCellType == BufferCellType.Leading ^ charLength == 2) { - throw PSTraceSource.NewArgumentException("fill"); + throw PSTraceSource.NewArgumentException(nameof(fill)); } } } @@ -1091,14 +1091,14 @@ public override // make sure the rect is valid if (region.Right < region.Left) { - throw PSTraceSource.NewArgumentException("region", + throw PSTraceSource.NewArgumentException(nameof(region), ConsoleHostRawUserInterfaceStrings.InvalidRegionErrorTemplate, "region.Right", "region.Left"); } if (region.Bottom < region.Top) { - throw PSTraceSource.NewArgumentException("region", + throw PSTraceSource.NewArgumentException(nameof(region), ConsoleHostRawUserInterfaceStrings.InvalidRegionErrorTemplate, "region.Bottom", "region.Top"); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs index cd455c0f989..9449669ab65 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs @@ -97,12 +97,12 @@ public override if (descriptions == null) { - throw PSTraceSource.NewArgumentNullException("descriptions"); + throw PSTraceSource.NewArgumentNullException(nameof(descriptions)); } if (descriptions.Count < 1) { - throw PSTraceSource.NewArgumentException("descriptions", + throw PSTraceSource.NewArgumentException(nameof(descriptions), ConsoleHostUserInterfaceStrings.PromptEmptyDescriptionsErrorTemplate, "descriptions"); } @@ -139,7 +139,7 @@ public override descIndex++; if (desc == null) { - throw PSTraceSource.NewArgumentException("descriptions", + throw PSTraceSource.NewArgumentException(nameof(descriptions), ConsoleHostUserInterfaceStrings.NullErrorTemplate, string.Format(CultureInfo.InvariantCulture, "descriptions[{0}]", descIndex)); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs index 1988104dbdb..70163c865e4 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs @@ -46,18 +46,18 @@ public override int PromptForChoice(string caption, string message, Collection= choices.Count)) { - throw PSTraceSource.NewArgumentOutOfRangeException("defaultChoice", defaultChoice, + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(defaultChoice), defaultChoice, ConsoleHostUserInterfaceStrings.InvalidDefaultChoiceErrorTemplate, "defaultChoice", "choice"); } @@ -175,12 +175,12 @@ public Collection PromptForChoice(string caption, if (choices == null) { - throw PSTraceSource.NewArgumentNullException("choices"); + throw PSTraceSource.NewArgumentNullException(nameof(choices)); } if (choices.Count == 0) { - throw PSTraceSource.NewArgumentException("choices", + throw PSTraceSource.NewArgumentException(nameof(choices), ConsoleHostUserInterfaceStrings.EmptyChoicesErrorTemplate, "choices"); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs index c2a13132e41..55dba38d6b4 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs @@ -27,7 +27,7 @@ class ProgressPane internal ProgressPane(ConsoleHostUserInterface ui) { - if (ui == null) throw new ArgumentNullException("ui"); + if (ui == null) throw new ArgumentNullException(nameof(ui)); _ui = ui; _rawui = ui.RawUI; } diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs index e01249c9bc5..7cfef28f7e5 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs @@ -38,12 +38,12 @@ long keywords { if (id < 0) { - throw new ArgumentOutOfRangeException("id", DotNetEventingStrings.ArgumentOutOfRange_NeedNonNegNum); + throw new ArgumentOutOfRangeException(nameof(id), DotNetEventingStrings.ArgumentOutOfRange_NeedNonNegNum); } if (id > ushort.MaxValue) { - throw new ArgumentOutOfRangeException("id", string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_NeedValidId, 1, ushort.MaxValue)); + throw new ArgumentOutOfRangeException(nameof(id), string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_NeedValidId, 1, ushort.MaxValue)); } _id = (ushort)id; @@ -55,12 +55,12 @@ long keywords if (task < 0) { - throw new ArgumentOutOfRangeException("task", DotNetEventingStrings.ArgumentOutOfRange_NeedNonNegNum); + throw new ArgumentOutOfRangeException(nameof(task), DotNetEventingStrings.ArgumentOutOfRange_NeedNonNegNum); } if (task > ushort.MaxValue) { - throw new ArgumentOutOfRangeException("task", string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_NeedValidId, 1, ushort.MaxValue)); + throw new ArgumentOutOfRangeException(nameof(task), string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_NeedValidId, 1, ushort.MaxValue)); } _task = (ushort)task; diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs index 05628d51f8d..1d2038b5bf1 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs @@ -435,7 +435,7 @@ public bool WriteMessageEvent(string eventMessage, byte eventLevel, long eventKe if (eventMessage == null) { - throw new ArgumentNullException("eventMessage"); + throw new ArgumentNullException(nameof(eventMessage)); } if (IsEnabled(eventLevel, eventKeywords)) @@ -619,7 +619,7 @@ public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid related // // too many arguments to log // - throw new ArgumentOutOfRangeException("eventPayload", + throw new ArgumentOutOfRangeException(nameof(eventPayload), string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_MaxArgExceeded, s_etwMaxNumberArguments)); } @@ -656,7 +656,7 @@ public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid related } else { - throw new ArgumentOutOfRangeException("eventPayload", + throw new ArgumentOutOfRangeException(nameof(eventPayload), string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_MaxStringsExceeded, s_etwAPIMaxStringCount)); } } diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs index 2c272226ae2..27b24de945e 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs @@ -70,7 +70,7 @@ public EventProviderTraceListener(string providerId, string name, string delimit : base(name) { if (delimiter == null) - throw new ArgumentNullException("delimiter"); + throw new ArgumentNullException(nameof(delimiter)); if (delimiter.Length == 0) throw new ArgumentException(DotNetEventingStrings.Argument_NeedNonemptyDelimiter); diff --git a/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs b/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs index 83e99298979..8e6d5ba9967 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs @@ -287,7 +287,7 @@ public VT100EscapeSequences(PSMarkdownOptionInfo optionInfo) { if (optionInfo == null) { - throw new ArgumentNullException("optionInfo"); + throw new ArgumentNullException(nameof(optionInfo)); } options = optionInfo; diff --git a/src/Microsoft.PowerShell.Security/security/AclCommands.cs b/src/Microsoft.PowerShell.Security/security/AclCommands.cs index 9cdae9175ae..7447318f054 100644 --- a/src/Microsoft.PowerShell.Security/security/AclCommands.cs +++ b/src/Microsoft.PowerShell.Security/security/AclCommands.cs @@ -178,7 +178,7 @@ public static string GetPath(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } else { @@ -205,13 +205,13 @@ public static string GetOwner(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } ObjectSecurity sd = instance.BaseObject as ObjectSecurity; if (sd == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } // Get owner @@ -245,13 +245,13 @@ public static string GetGroup(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } ObjectSecurity sd = instance.BaseObject as ObjectSecurity; if (sd == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } // Get Group @@ -284,13 +284,13 @@ public static AuthorizationRuleCollection GetAccess(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } ObjectSecurity sd = instance.BaseObject as ObjectSecurity; if (sd == null) { - PSTraceSource.NewArgumentException("instance"); + PSTraceSource.NewArgumentException(nameof(instance)); } // Get DACL @@ -323,13 +323,13 @@ public static AuthorizationRuleCollection GetAudit(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } ObjectSecurity sd = instance.BaseObject as ObjectSecurity; if (sd == null) { - PSTraceSource.NewArgumentException("instance"); + PSTraceSource.NewArgumentException(nameof(instance)); } AuthorizationRuleCollection sacl; @@ -585,13 +585,13 @@ public static string GetSddl(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } ObjectSecurity sd = instance.BaseObject as ObjectSecurity; if (sd == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } string sddl = sd.GetSecurityDescriptorSddlForm(AccessControlSections.All); diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index 7bdb8286598..cde06e0ed65 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -605,7 +605,7 @@ public CertificateProvider() X509StoreLocation user = new X509StoreLocation(StoreLocation.CurrentUser); s_storeLocations.Add(user); - AddItemToCache(StoreLocation.CurrentUser.ToString(), + AddItemToCache(nameof(StoreLocation.CurrentUser), user); // @@ -614,7 +614,7 @@ public CertificateProvider() X509StoreLocation machine = new X509StoreLocation(StoreLocation.LocalMachine); s_storeLocations.Add(machine); - AddItemToCache(StoreLocation.LocalMachine.ToString(), + AddItemToCache(nameof(StoreLocation.LocalMachine), machine); AddItemToCache(string.Empty, s_storeLocations); @@ -1324,7 +1324,7 @@ private string MyGetChildName(string path) if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } // Normalize the path diff --git a/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs b/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs index ae9004f8dcf..91a3e8e3a83 100644 --- a/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs +++ b/src/Microsoft.PowerShell.Security/security/SignatureCommands.cs @@ -555,7 +555,7 @@ protected override Signature PerformAction(string filePath) System.Globalization.CultureInfo.CurrentCulture, UtilsStrings.FileSmallerThan4Bytes, filePath); - PSArgumentException e = new PSArgumentException(message, "filePath"); + PSArgumentException e = new PSArgumentException(message, nameof(filePath)); ErrorRecord er = SecurityUtils.CreateInvalidArgumentErrorRecord( e, "SignatureCommandsBaseFileSmallerThan4Bytes" diff --git a/src/Microsoft.WSMan.Management/CurrentConfigurations.cs b/src/Microsoft.WSMan.Management/CurrentConfigurations.cs index 42709bc8337..01ba71f68a7 100644 --- a/src/Microsoft.WSMan.Management/CurrentConfigurations.cs +++ b/src/Microsoft.WSMan.Management/CurrentConfigurations.cs @@ -63,7 +63,7 @@ public CurrentConfigurations(IWSManSession serverSession) { if (serverSession == null) { - throw new ArgumentNullException("serverSession"); + throw new ArgumentNullException(nameof(serverSession)); } this.rootDocument = new XmlDocument(); @@ -81,7 +81,7 @@ public bool RefreshCurrentConfiguration(string responseOfGet) { if (string.IsNullOrEmpty(responseOfGet)) { - throw new ArgumentNullException("responseOfGet"); + throw new ArgumentNullException(nameof(responseOfGet)); } this.rootDocument.LoadXml(responseOfGet); @@ -103,7 +103,7 @@ public void PutConfigurationOnServer(string resourceUri) { if (string.IsNullOrEmpty(resourceUri)) { - throw new ArgumentNullException("resourceUri"); + throw new ArgumentNullException(nameof(resourceUri)); } this.serverSession.Put(resourceUri, this.rootDocument.InnerXml, 0); @@ -119,7 +119,7 @@ public void RemoveOneConfiguration(string pathToNodeFromRoot) { if (pathToNodeFromRoot == null) { - throw new ArgumentNullException("pathToNodeFromRoot"); + throw new ArgumentNullException(nameof(pathToNodeFromRoot)); } XmlNode nodeToRemove = @@ -136,7 +136,7 @@ public void RemoveOneConfiguration(string pathToNodeFromRoot) } else { - throw new ArgumentException("Node is not present in the XML, Please give valid XPath", "pathToNodeFromRoot"); + throw new ArgumentException("Node is not present in the XML, Please give valid XPath", nameof(pathToNodeFromRoot)); } } @@ -152,17 +152,17 @@ public void UpdateOneConfiguration(string pathToNodeFromRoot, string configurati { if (pathToNodeFromRoot == null) { - throw new ArgumentNullException("pathToNodeFromRoot"); + throw new ArgumentNullException(nameof(pathToNodeFromRoot)); } if (string.IsNullOrEmpty(configurationName)) { - throw new ArgumentNullException("configurationName"); + throw new ArgumentNullException(nameof(configurationName)); } if (configurationValue == null) { - throw new ArgumentNullException("configurationValue"); + throw new ArgumentNullException(nameof(configurationValue)); } XmlNode nodeToUpdate = @@ -197,7 +197,7 @@ public string GetOneConfiguration(string pathFromRoot) { if (pathFromRoot == null) { - throw new ArgumentNullException("pathFromRoot"); + throw new ArgumentNullException(nameof(pathFromRoot)); } XmlNode requiredNode = diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index 32e1f88e57b..23593d68628 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -180,12 +180,12 @@ private static string FormatResourceMsgFromResourcetextS( { if (resourceManager == null) { - throw new ArgumentNullException("resourceManager"); + throw new ArgumentNullException(nameof(resourceManager)); } if (string.IsNullOrEmpty(resourceName)) { - throw new ArgumentNullException("resourceName"); + throw new ArgumentNullException(nameof(resourceName)); } string template = resourceManager.GetString(resourceName); @@ -478,7 +478,7 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, if (string.IsNullOrEmpty(entry.Key.ToString())) { // XmlNode newnode = xmlfile.CreateNode(XmlNodeType.Attribute, ATTR_NIL_NAME, NS_XSI_URI); - XmlAttribute newnode = xmlfile.CreateAttribute(XmlNodeType.Attribute.ToString(), ATTR_NIL_NAME, NS_XSI_URI); + XmlAttribute newnode = xmlfile.CreateAttribute(nameof(XmlNodeType.Attribute), ATTR_NIL_NAME, NS_XSI_URI); newnode.Value = "true"; node.Attributes.Append(newnode); // (newnode.Attributes.Item(0).FirstChild ); diff --git a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs index fafd27c2cc4..ef210304ae9 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs @@ -78,7 +78,7 @@ private PowerShellAssemblyLoadContext(string basePaths) if (!Directory.Exists(basePath)) { string message = string.Format(CultureInfo.CurrentCulture, BaseFolderDoesNotExist, basePath); - throw new ArgumentException(message, "basePaths"); + throw new ArgumentException(message, nameof(basePaths)); } _probingPaths[i] = basePath.Trim(); @@ -582,7 +582,7 @@ public class PowerShellAssemblyLoadContextInitializer public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)]string basePaths) { if (string.IsNullOrEmpty(basePaths)) - throw new ArgumentNullException("basePaths"); + throw new ArgumentNullException(nameof(basePaths)); PowerShellAssemblyLoadContext.InitializeSingleton(basePaths); } diff --git a/src/System.Management.Automation/DscSupport/CimDSCParser.cs b/src/System.Management.Automation/DscSupport/CimDSCParser.cs index c5fd73bf5b1..908025c14e2 100644 --- a/src/System.Management.Automation/DscSupport/CimDSCParser.cs +++ b/src/System.Management.Automation/DscSupport/CimDSCParser.cs @@ -298,7 +298,7 @@ public override object Transform(EngineIntrinsics engineIntrinsics, object input if (engineIntrinsics == null) { - throw PSTraceSource.NewArgumentNullException("engineIntrinsics"); + throw PSTraceSource.NewArgumentNullException(nameof(engineIntrinsics)); } return PsUtils.EvaluatePowerShellDataFileAsModuleManifest( @@ -372,7 +372,7 @@ internal static byte[] GetFileContent(string fullFilePath) { if (string.IsNullOrEmpty(fullFilePath)) { - throw PSTraceSource.NewArgumentNullException("fullFilePath"); + throw PSTraceSource.NewArgumentNullException(nameof(fullFilePath)); } if (!File.Exists(fullFilePath)) @@ -951,7 +951,7 @@ public static List ImportClasses(string path, Tuple m { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } s_tracer.WriteLine("DSC ClassCache: importing file: {0}", path); @@ -1179,7 +1179,7 @@ public static List GetCachedClassByFileName(string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { - throw PSTraceSource.NewArgumentNullException("fileName"); + throw PSTraceSource.NewArgumentNullException(nameof(fileName)); } List listCimClass; @@ -1197,7 +1197,7 @@ public static List GetCachedClassByModuleName(string moduleName) { if (string.IsNullOrWhiteSpace(moduleName)) { - throw PSTraceSource.NewArgumentNullException("moduleName"); + throw PSTraceSource.NewArgumentNullException(nameof(moduleName)); } var moduleFileName = moduleName + ".schema.mof"; @@ -1214,7 +1214,7 @@ public static List ImportInstances(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } var parser = new Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser(MyClassCallback); @@ -1256,7 +1256,7 @@ public static void ValidateInstanceText(string instanceText) { if (string.IsNullOrEmpty(instanceText)) { - throw PSTraceSource.NewArgumentNullException("instanceText"); + throw PSTraceSource.NewArgumentNullException(nameof(instanceText)); } var parser = new Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser(MyClassCallback); @@ -3220,12 +3220,12 @@ public static bool ImportCimKeywordsFromModule(PSModuleInfo module, string resou { if (module == null) { - throw PSTraceSource.NewArgumentNullException("module"); + throw PSTraceSource.NewArgumentNullException(nameof(module)); } if (resourceName == null) { - throw PSTraceSource.NewArgumentNullException("resourceName"); + throw PSTraceSource.NewArgumentNullException(nameof(resourceName)); } string dscResourcesPath = Path.Combine(module.ModuleBase, "DscResources"); @@ -3332,12 +3332,12 @@ public static bool ImportScriptKeywordsFromModule(PSModuleInfo module, string re { if (module == null) { - throw PSTraceSource.NewArgumentNullException("module"); + throw PSTraceSource.NewArgumentNullException(nameof(module)); } if (resourceName == null) { - throw PSTraceSource.NewArgumentNullException("resourceName"); + throw PSTraceSource.NewArgumentNullException(nameof(resourceName)); } schemaFilePath = Path.Combine(Path.Combine(Path.Combine(module.ModuleBase, "DscResources"), resourceName), resourceName + ".Schema.psm1"); diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs index 6574914c396..e03b4ae61eb 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs @@ -18,7 +18,7 @@ internal sealed class TerminatingErrorContext internal TerminatingErrorContext(PSCmdlet command) { if (command == null) - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); _command = command; } diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommandParameters.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommandParameters.cs index 26e62bc8a79..cdd60637a7a 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommandParameters.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommandParameters.cs @@ -171,7 +171,7 @@ internal override object Verify(object val, { if (val == null) { - throw PSTraceSource.NewArgumentNullException("val"); + throw PSTraceSource.NewArgumentNullException(nameof(val)); } // need to check the type: @@ -201,7 +201,7 @@ internal override object Verify(object val, return ex; } - PSTraceSource.NewArgumentException("val"); + PSTraceSource.NewArgumentException(nameof(val)); return null; } diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs index 5025fc6c381..4467744a666 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs @@ -510,7 +510,7 @@ private void ProcessPayload(FormatEntryData fed, FormatMessagesContextManager.Ou // we assume FormatEntryData as a standard wrapper if (fed == null) { - PSTraceSource.NewArgumentNullException("fed"); + PSTraceSource.NewArgumentNullException(nameof(fed)); } if (fed.formatEntryInfo == null) diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs index da440d8f628..6b647bd0912 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs @@ -87,7 +87,7 @@ protected FormatTableLoadException(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } int errorCount = info.GetInt32("ErrorCount"); @@ -114,7 +114,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -207,7 +207,7 @@ public FormatTable(IEnumerable formatFiles) : this(formatFiles, null, nu public void AppendFormatData(IEnumerable formatData) { if (formatData == null) - throw PSTraceSource.NewArgumentNullException("formatData"); + throw PSTraceSource.NewArgumentNullException(nameof(formatData)); _formatDBMgr.AddFormatData(formatData, false); } @@ -226,7 +226,7 @@ public void AppendFormatData(IEnumerable formatData) public void PrependFormatData(IEnumerable formatData) { if (formatData == null) - throw PSTraceSource.NewArgumentNullException("formatData"); + throw PSTraceSource.NewArgumentNullException(nameof(formatData)); _formatDBMgr.AddFormatData(formatData, true); } @@ -253,7 +253,7 @@ internal FormatTable(IEnumerable formatFiles, AuthorizationManager autho { if (formatFiles == null) { - throw PSTraceSource.NewArgumentNullException("formatFiles"); + throw PSTraceSource.NewArgumentNullException(nameof(formatFiles)); } _formatDBMgr = new TypeInfoDataBaseManager(formatFiles, true, authorizationManager, host); diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs index 50f687c46d1..64af2244fb8 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs @@ -376,22 +376,22 @@ internal static string GetControlShapeName(ControlBase control) { if (control is TableControlBody) { - return FormatShape.Table.ToString(); + return nameof(FormatShape.Table); } if (control is ListControlBody) { - return FormatShape.List.ToString(); + return nameof(FormatShape.List); } if (control is WideControlBody) { - return FormatShape.Wide.ToString(); + return nameof(FormatShape.Wide); } if (control is ComplexControlBody) { - return FormatShape.Complex.ToString(); + return nameof(FormatShape.Complex); } return string.Empty; @@ -635,9 +635,9 @@ public override string ToString() public ExtendedTypeDefinition(string typeName, IEnumerable viewDefinitions) : this() { if (string.IsNullOrEmpty(typeName)) - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); if (viewDefinitions == null) - throw PSTraceSource.NewArgumentNullException("viewDefinitions"); + throw PSTraceSource.NewArgumentNullException(nameof(viewDefinitions)); TypeNames.Add(typeName); foreach (FormatViewDefinition definition in viewDefinitions) @@ -653,7 +653,7 @@ public ExtendedTypeDefinition(string typeName, IEnumerable public ExtendedTypeDefinition(string typeName) : this() { if (string.IsNullOrEmpty(typeName)) - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); TypeNames.Add(typeName); } @@ -691,9 +691,9 @@ internal FormatViewDefinition(string name, PSControl control, Guid instanceid) public FormatViewDefinition(string name, PSControl control) { if (string.IsNullOrEmpty(name)) - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); if (control == null) - throw PSTraceSource.NewArgumentNullException("control"); + throw PSTraceSource.NewArgumentNullException(nameof(control)); Name = name; Control = control; @@ -800,7 +800,7 @@ public DisplayEntry(string value, DisplayEntryValueType type) { if (string.IsNullOrEmpty(value)) if (value == null || type == DisplayEntryValueType.Property) - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); Value = value; ValueType = type; diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Complex.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Complex.cs index 6e11d21647a..d3290c18752 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Complex.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Complex.cs @@ -420,13 +420,13 @@ public CustomEntryBuilder StartFrame(uint leftIndent = 0, uint rightIndent = 0, // Mutually exclusive if (leftIndent != 0 && rightIndent != 0) { - throw PSTraceSource.NewArgumentException("leftIndent"); + throw PSTraceSource.NewArgumentException(nameof(leftIndent)); } // Mutually exclusive if (firstLineHanging != 0 && firstLineIndent != 0) { - throw PSTraceSource.NewArgumentException("firstLineHanging"); + throw PSTraceSource.NewArgumentException(nameof(firstLineHanging)); } var frame = new CustomItemFrame diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_List.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_List.cs index 06a330c0264..6025acfff44 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_List.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_List.cs @@ -173,7 +173,7 @@ public ListControl(IEnumerable entries) : this() { if (entries == null) - throw PSTraceSource.NewArgumentNullException("entries"); + throw PSTraceSource.NewArgumentNullException(nameof(entries)); foreach (ListControlEntry entry in entries) { this.Entries.Add(entry); @@ -242,7 +242,7 @@ public ListControlEntry(IEnumerable listItems) : this() { if (listItems == null) - throw PSTraceSource.NewArgumentNullException("listItems"); + throw PSTraceSource.NewArgumentNullException(nameof(listItems)); foreach (ListControlEntryItem item in listItems) { this.Items.Add(item); @@ -253,9 +253,9 @@ public ListControlEntry(IEnumerable listItems) public ListControlEntry(IEnumerable listItems, IEnumerable selectedBy) { if (listItems == null) - throw PSTraceSource.NewArgumentNullException("listItems"); + throw PSTraceSource.NewArgumentNullException(nameof(listItems)); if (selectedBy == null) - throw PSTraceSource.NewArgumentNullException("selectedBy"); + throw PSTraceSource.NewArgumentNullException(nameof(selectedBy)); EntrySelectedBy = new EntrySelectedBy { TypeNames = new List(selectedBy) }; foreach (ListControlEntryItem item in listItems) diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs index 2afbab8a7e7..ddd8446b065 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs @@ -306,7 +306,7 @@ public TableControl(TableControlRow tableControlRow, IEnumerable columns) : this() { if (columns == null) - throw PSTraceSource.NewArgumentNullException("columns"); + throw PSTraceSource.NewArgumentNullException(nameof(columns)); foreach (TableControlColumn column in columns) { Columns.Add(column); @@ -507,7 +507,7 @@ internal TableRowDefinitionBuilder(TableControlBuilder tcb, TableControlRow tcr) private TableRowDefinitionBuilder AddItem(string value, DisplayEntryValueType entryType, Alignment alignment, string format) { if (string.IsNullOrEmpty(value)) - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException(nameof(value)); var tableControlColumn = new TableControlColumn(alignment, new DisplayEntry(value, entryType)) { diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Wide.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Wide.cs index 2b4dd913f94..0e140fa5eea 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Wide.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Wide.cs @@ -145,7 +145,7 @@ internal WideControl(WideControlBody widecontrolbody, ViewDefinition viewDefinit public WideControl(IEnumerable wideEntries) : this() { if (wideEntries == null) - throw PSTraceSource.NewArgumentNullException("wideEntries"); + throw PSTraceSource.NewArgumentNullException(nameof(wideEntries)); foreach (WideControlEntryItem entryItem in wideEntries) { @@ -157,7 +157,7 @@ public WideControl(IEnumerable wideEntries) : this() public WideControl(IEnumerable wideEntries, uint columns) : this() { if (wideEntries == null) - throw PSTraceSource.NewArgumentNullException("wideEntries"); + throw PSTraceSource.NewArgumentNullException(nameof(wideEntries)); foreach (WideControlEntryItem entryItem in wideEntries) { @@ -224,7 +224,7 @@ internal WideControlEntryItem(WideControlEntryDefinition definition) : this() public WideControlEntryItem(DisplayEntry entry) : this() { if (entry == null) - throw PSTraceSource.NewArgumentNullException("entry"); + throw PSTraceSource.NewArgumentNullException(nameof(entry)); this.DisplayEntry = entry; } @@ -234,9 +234,9 @@ public WideControlEntryItem(DisplayEntry entry) : this() public WideControlEntryItem(DisplayEntry entry, IEnumerable selectedBy) : this() { if (entry == null) - throw PSTraceSource.NewArgumentNullException("entry"); + throw PSTraceSource.NewArgumentNullException(nameof(entry)); if (selectedBy == null) - throw PSTraceSource.NewArgumentNullException("selectedBy"); + throw PSTraceSource.NewArgumentNullException(nameof(selectedBy)); this.DisplayEntry = entry; this.EntrySelectedBy = EntrySelectedBy.Get(selectedBy, null); diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataManager.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataManager.cs index d03d2eb1ad3..21a180baf62 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataManager.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataManager.cs @@ -79,7 +79,7 @@ internal TypeInfoDataBaseManager( { if (string.IsNullOrEmpty(formatFile) || (!Path.IsPathRooted(formatFile))) { - throw PSTraceSource.NewArgumentException("formatFiles", FormatAndOutXmlLoadingStrings.FormatFileNotRooted, formatFile); + throw PSTraceSource.NewArgumentException(nameof(formatFiles), FormatAndOutXmlLoadingStrings.FormatFileNotRooted, formatFile); } PSSnapInTypeAndFormatErrors fileToLoad = new PSSnapInTypeAndFormatErrors(string.Empty, formatFile); @@ -122,7 +122,7 @@ internal void Add(string formatFile, bool shouldPrepend) { if (string.IsNullOrEmpty(formatFile) || (!Path.IsPathRooted(formatFile))) { - throw PSTraceSource.NewArgumentException("formatFile", FormatAndOutXmlLoadingStrings.FormatFileNotRooted, formatFile); + throw PSTraceSource.NewArgumentException(nameof(formatFile), FormatAndOutXmlLoadingStrings.FormatFileNotRooted, formatFile); } lock (_formatFileList) diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs index 82277eeebd1..79bcbd61dca 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs @@ -193,16 +193,16 @@ internal bool LoadXmlFile( bool preValidated) { if (info == null) - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); if (info.filePath == null) throw PSTraceSource.NewArgumentNullException("info.filePath"); if (db == null) - throw PSTraceSource.NewArgumentNullException("db"); + throw PSTraceSource.NewArgumentNullException(nameof(db)); if (expressionFactory == null) - throw PSTraceSource.NewArgumentNullException("expressionFactory"); + throw PSTraceSource.NewArgumentNullException(nameof(expressionFactory)); if (SecuritySupport.IsProductBinary(info.filePath)) { @@ -288,13 +288,13 @@ internal bool LoadFormattingData( bool isForHelp) { if (typeDefinition == null) - throw PSTraceSource.NewArgumentNullException("typeDefinition"); + throw PSTraceSource.NewArgumentNullException(nameof(typeDefinition)); if (typeDefinition.TypeName == null) throw PSTraceSource.NewArgumentNullException("typeDefinition.TypeName"); if (db == null) - throw PSTraceSource.NewArgumentNullException("db"); + throw PSTraceSource.NewArgumentNullException(nameof(db)); if (expressionFactory == null) - throw PSTraceSource.NewArgumentNullException("expressionFactory"); + throw PSTraceSource.NewArgumentNullException(nameof(expressionFactory)); this.expressionFactory = expressionFactory; this.ReportTrace("loading ExtendedTypeDefinition started"); @@ -337,10 +337,10 @@ internal bool LoadFormattingData( private void LoadData(XmlDocument doc, TypeInfoDataBase db) { if (doc == null) - throw PSTraceSource.NewArgumentNullException("doc"); + throw PSTraceSource.NewArgumentNullException(nameof(doc)); if (db == null) - throw PSTraceSource.NewArgumentNullException("db"); + throw PSTraceSource.NewArgumentNullException(nameof(db)); // create a new instance of the database to be loaded XmlElement documentElement = doc.DocumentElement; @@ -428,7 +428,7 @@ private void LoadData(ExtendedTypeDefinition typeDefinition, TypeInfoDataBase db throw PSTraceSource.NewArgumentNullException("viewDefinition"); if (db == null) - throw PSTraceSource.NewArgumentNullException("db"); + throw PSTraceSource.NewArgumentNullException(nameof(db)); int viewIndex = 0; foreach (FormatViewDefinition formatView in typeDefinition.FormatViewDefinition) @@ -2054,7 +2054,7 @@ internal ViewEntryNodeMatch(TypeInfoDataBaseLoader loader) internal bool ProcessExpressionDirectives(XmlNode containerNode, List unprocessedNodes) { if (containerNode == null) - throw PSTraceSource.NewArgumentNullException("containerNode"); + throw PSTraceSource.NewArgumentNullException(nameof(containerNode)); string formatString = null; TextToken textToken = null; diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs index 66d819a0f1e..34702849d14 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs @@ -201,10 +201,10 @@ private bool LoadMainControlDependentData(List unprocessedNodes, ViewDe private bool LoadCommonViewData(XmlNode viewNode, ViewDefinition view, List unprocessedNodes) { if (viewNode == null) - throw PSTraceSource.NewArgumentNullException("viewNode"); + throw PSTraceSource.NewArgumentNullException(nameof(viewNode)); if (view == null) - throw PSTraceSource.NewArgumentNullException("view"); + throw PSTraceSource.NewArgumentNullException(nameof(view)); // set loading information view.loadingInfo = this.LoadingInfo; diff --git a/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Complex.cs b/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Complex.cs index eeacaad4520..c9cd80bbee8 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Complex.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Complex.cs @@ -93,7 +93,7 @@ internal void GenerateFormatEntries(int maxTreeDepth, ControlBase control, { if (control == null) { - throw PSTraceSource.NewArgumentNullException("control"); + throw PSTraceSource.NewArgumentNullException(nameof(control)); } ExecuteFormatControl(new TraversalInfo(0, maxTreeDepth), control, @@ -190,7 +190,7 @@ private void ExecuteFormatTokenList(TraversalInfo level, { if (so == null) { - throw PSTraceSource.NewArgumentNullException("so"); + throw PSTraceSource.NewArgumentNullException(nameof(so)); } // guard against infinite loop diff --git a/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs b/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs index dd0dbf4738e..3e8c320390b 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs @@ -142,7 +142,7 @@ private void ProcessUnknownInvalidClassId(string classId, object obj, string err string msg = StringUtil.Format(FormatAndOut_format_xxx.FOD_ClassIdInvalid, classId); ErrorRecord errorRecord = new ErrorRecord( - PSTraceSource.NewArgumentException("classId"), + PSTraceSource.NewArgumentException(nameof(classId)), errorId, ErrorCategory.InvalidData, obj); @@ -217,7 +217,7 @@ internal FormatInfoData DeserializeMemberObject(PSObject so, string property) string msg = StringUtil.Format(FormatAndOut_format_xxx.FOD_RecursiveProperty, property); ErrorRecord errorRecord = new ErrorRecord( - PSTraceSource.NewArgumentException("property"), + PSTraceSource.NewArgumentException(nameof(property)), "FormatObjectDeserializerRecursiveProperty", ErrorCategory.InvalidData, so); @@ -247,7 +247,7 @@ private object DeserializeMemberVariable(PSObject so, string property, System.Ty string msg = StringUtil.Format(FormatAndOut_format_xxx.FOD_InvalidPropertyType, t.Name, property); ErrorRecord errorRecord = new ErrorRecord( - PSTraceSource.NewArgumentException("property"), + PSTraceSource.NewArgumentException(nameof(property)), "FormatObjectDeserializerInvalidPropertyType", ErrorCategory.InvalidData, so); @@ -392,7 +392,7 @@ internal static FormatInfoData CreateInstance(PSObject so, FormatObjectDeseriali { if (so == null) { - throw PSTraceSource.NewArgumentNullException("so"); + throw PSTraceSource.NewArgumentNullException(nameof(so)); } // look for the property that defines the type of object @@ -421,7 +421,7 @@ private static FormatInfoData CreateInstance(string clsid, FormatObjectDeseriali Func ctor; if (!s_constructors.TryGetValue(clsid, out ctor)) { - CreateInstanceError(PSTraceSource.NewArgumentException("clsid"), clsid, deserializer); + CreateInstanceError(PSTraceSource.NewArgumentException(nameof(clsid)), clsid, deserializer); return null; } @@ -504,7 +504,7 @@ internal static void ReadList(PSObject so, string property, List lst, FormatO { if (lst == null) { - throw PSTraceSource.NewArgumentNullException("lst"); + throw PSTraceSource.NewArgumentNullException(nameof(lst)); } object memberRaw = FormatObjectDeserializer.GetProperty(so, property); diff --git a/src/System.Management.Automation/FormatAndOutput/common/ILineOutput.cs b/src/System.Management.Automation/FormatAndOutput/common/ILineOutput.cs index 03cd5a1a2a2..09432253e33 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/ILineOutput.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/ILineOutput.cs @@ -282,9 +282,9 @@ internal class WriteLineHelper internal WriteLineHelper(bool lineWrap, WriteCallback wlc, WriteCallback wc, DisplayCells displayCells) { if (wlc == null) - throw PSTraceSource.NewArgumentNullException("wlc"); + throw PSTraceSource.NewArgumentNullException(nameof(wlc)); if (displayCells == null) - throw PSTraceSource.NewArgumentNullException("displayCells"); + throw PSTraceSource.NewArgumentNullException(nameof(displayCells)); _displayCells = displayCells; _writeLineCall = wlc; @@ -474,7 +474,7 @@ internal StreamingTextWriter(WriteLineCallback writeCall, CultureInfo culture) : base(culture) { if (writeCall == null) - throw PSTraceSource.NewArgumentNullException("writeCall"); + throw PSTraceSource.NewArgumentNullException(nameof(writeCall)); _writeCall = writeCall; } diff --git a/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameter.cs b/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameter.cs index 3de036f35da..15aecfacc8f 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameter.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameter.cs @@ -140,7 +140,7 @@ internal CommandParameterDefinition() internal HashtableEntryDefinition MatchEntry(string keyName, TerminatingErrorContext invocationContext) { if (string.IsNullOrEmpty(keyName)) - PSTraceSource.NewArgumentNullException("keyName"); + PSTraceSource.NewArgumentNullException(nameof(keyName)); HashtableEntryDefinition matchingEntry = null; for (int k = 0; k < this.hashEntries.Count; k++) diff --git a/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameterAssociation.cs b/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameterAssociation.cs index 25e7fd61250..7042bf85dd1 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameterAssociation.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/Utilities/MshParameterAssociation.cs @@ -23,7 +23,7 @@ internal sealed class MshResolvedExpressionParameterAssociation internal MshResolvedExpressionParameterAssociation(MshParameter parameter, PSPropertyExpression expression) { if (expression == null) - throw PSTraceSource.NewArgumentNullException("expression"); + throw PSTraceSource.NewArgumentNullException(nameof(expression)); OriginatingParameter = parameter; ResolvedExpression = expression; diff --git a/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs b/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs index dd9f18a2502..4279406e578 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/Utilities/Mshexpression.cs @@ -71,7 +71,7 @@ public PSPropertyExpression(string s, bool isResolved) { if (string.IsNullOrEmpty(s)) { - throw PSTraceSource.NewArgumentNullException("s"); + throw PSTraceSource.NewArgumentNullException(nameof(s)); } _stringValue = s; @@ -87,7 +87,7 @@ public PSPropertyExpression(ScriptBlock scriptBlock) { if (scriptBlock == null) { - throw PSTraceSource.NewArgumentNullException("scriptBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock)); } Script = scriptBlock; diff --git a/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs b/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs index 0b2dfe2f721..b0fe26cfd49 100644 --- a/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs +++ b/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs @@ -252,9 +252,9 @@ internal override DisplayCells DisplayCells internal ConsoleLineOutput(PSHostUserInterface hostConsole, bool paging, TerminatingErrorContext errorContext) { if (hostConsole == null) - throw PSTraceSource.NewArgumentNullException("hostConsole"); + throw PSTraceSource.NewArgumentNullException(nameof(hostConsole)); if (errorContext == null) - throw PSTraceSource.NewArgumentNullException("errorContext"); + throw PSTraceSource.NewArgumentNullException(nameof(errorContext)); _console = hostConsole; _errorContext = errorContext; @@ -474,7 +474,7 @@ private class PromptHandler internal PromptHandler(string s, ConsoleLineOutput cmdlet) { if (string.IsNullOrEmpty(s)) - throw PSTraceSource.NewArgumentNullException("s"); + throw PSTraceSource.NewArgumentNullException(nameof(s)); _promptString = s; _callingCmdlet = cmdlet; diff --git a/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs b/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs index 44cda85e582..81a4c33062f 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs @@ -21,8 +21,8 @@ public sealed class MethodInvocationInfo /// Return value of the method (ok to pass null if the method doesn't return anything). public MethodInvocationInfo(string name, IEnumerable parameters, MethodParameter returnValue) { - if (name == null) throw new ArgumentNullException("name"); - if (parameters == null) throw new ArgumentNullException("parameters"); + if (name == null) throw new ArgumentNullException(nameof(name)); + if (parameters == null) throw new ArgumentNullException(nameof(parameters)); // returnValue can be null MethodName = name; diff --git a/src/System.Management.Automation/cimSupport/cmdletization/ObjectModelWrapper.cs b/src/System.Management.Automation/cimSupport/cmdletization/ObjectModelWrapper.cs index 4851bf1f9da..289ad0c3a76 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/ObjectModelWrapper.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/ObjectModelWrapper.cs @@ -19,22 +19,22 @@ internal void Initialize(PSCmdlet cmdlet, string className, string classVersion, { if (cmdlet == null) { - throw new ArgumentNullException("cmdlet"); + throw new ArgumentNullException(nameof(cmdlet)); } if (string.IsNullOrEmpty(className)) { - throw new ArgumentNullException("className"); + throw new ArgumentNullException(nameof(className)); } if (classVersion == null) // possible and ok to have classVersion==string.Empty { - throw new ArgumentNullException("classVersion"); + throw new ArgumentNullException(nameof(classVersion)); } if (privateData == null) { - throw new ArgumentNullException("privateData"); + throw new ArgumentNullException(nameof(privateData)); } _cmdlet = cmdlet; diff --git a/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs b/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs index 47fb00d2e32..3a7e29a4c14 100644 --- a/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs +++ b/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs @@ -105,7 +105,7 @@ public override PSAdaptedProperty GetProperty(object baseObject, string property { if (propertyName == null) { - throw new PSArgumentNullException("propertyName"); + throw new PSArgumentNullException(nameof(propertyName)); } // baseObject should never be null @@ -199,7 +199,7 @@ public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty) { if (adaptedProperty == null) { - throw new ArgumentNullException("adaptedProperty"); + throw new ArgumentNullException(nameof(adaptedProperty)); } CimProperty cimProperty = adaptedProperty.Tag as CimProperty; @@ -213,7 +213,7 @@ public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty) return ToStringCodeMethods.Type(typeof(string)); } - throw new ArgumentNullException("adaptedProperty"); + throw new ArgumentNullException(nameof(adaptedProperty)); } /// @@ -224,7 +224,7 @@ public override object GetPropertyValue(PSAdaptedProperty adaptedProperty) { if (adaptedProperty == null) { - throw new ArgumentNullException("adaptedProperty"); + throw new ArgumentNullException(nameof(adaptedProperty)); } CimProperty cimProperty = adaptedProperty.Tag as CimProperty; @@ -239,7 +239,7 @@ public override object GetPropertyValue(PSAdaptedProperty adaptedProperty) return cimInstance.GetCimSessionComputerName(); } - throw new ArgumentNullException("adaptedProperty"); + throw new ArgumentNullException(nameof(adaptedProperty)); } private void AddTypeNameHierarchy(IList typeNamesWithNamespace, IList typeNamesWithoutNamespace, string namespaceName, string className) @@ -288,7 +288,7 @@ public override Collection GetTypeNameHierarchy(object baseObject) var cimInstance = baseObject as CimInstance; if (cimInstance == null) { - throw new ArgumentNullException("baseObject"); + throw new ArgumentNullException(nameof(baseObject)); } var typeNamesWithNamespace = new List(); @@ -381,7 +381,7 @@ public override void SetPropertyValue(PSAdaptedProperty adaptedProperty, object { if (adaptedProperty == null) { - throw new ArgumentNullException("adaptedProperty"); + throw new ArgumentNullException(nameof(adaptedProperty)); } if (!IsSettable(adaptedProperty)) diff --git a/src/System.Management.Automation/engine/ApplicationInfo.cs b/src/System.Management.Automation/engine/ApplicationInfo.cs index 308cea39b64..9e785aee935 100644 --- a/src/System.Management.Automation/engine/ApplicationInfo.cs +++ b/src/System.Management.Automation/engine/ApplicationInfo.cs @@ -39,12 +39,12 @@ internal ApplicationInfo(string name, string path, ExecutionContext context) : b { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } Path = path; diff --git a/src/System.Management.Automation/engine/ChildrenCmdletProviderInterfaces.cs b/src/System.Management.Automation/engine/ChildrenCmdletProviderInterfaces.cs index 7fafdf84503..85cff4c8efb 100644 --- a/src/System.Management.Automation/engine/ChildrenCmdletProviderInterfaces.cs +++ b/src/System.Management.Automation/engine/ChildrenCmdletProviderInterfaces.cs @@ -35,7 +35,7 @@ internal ChildItemCmdletProviderIntrinsics(Cmdlet cmdlet) { if (cmdlet == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdlet)); } _cmdlet = cmdlet; @@ -55,7 +55,7 @@ internal ChildItemCmdletProviderIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/CmdletFamilyProviderInterfaces.cs b/src/System.Management.Automation/engine/CmdletFamilyProviderInterfaces.cs index 2ce58a04afb..27537b21601 100644 --- a/src/System.Management.Automation/engine/CmdletFamilyProviderInterfaces.cs +++ b/src/System.Management.Automation/engine/CmdletFamilyProviderInterfaces.cs @@ -38,7 +38,7 @@ internal ProviderIntrinsics(Cmdlet cmdlet) { if (cmdlet == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdlet)); } _cmdlet = cmdlet; @@ -59,7 +59,7 @@ internal ProviderIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } Item = new ItemCmdletProviderIntrinsics(sessionState); diff --git a/src/System.Management.Automation/engine/CmdletInfo.cs b/src/System.Management.Automation/engine/CmdletInfo.cs index 896763d9d74..2861fa3a8b6 100644 --- a/src/System.Management.Automation/engine/CmdletInfo.cs +++ b/src/System.Management.Automation/engine/CmdletInfo.cs @@ -44,7 +44,7 @@ internal CmdletInfo( { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } // Get the verb and noun from the name @@ -52,7 +52,7 @@ internal CmdletInfo( { throw PSTraceSource.NewArgumentException( - "name", + nameof(name), DiscoveryExceptions.InvalidCmdletNameFormat, name); } @@ -105,12 +105,12 @@ public CmdletInfo(string name, Type implementingType) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } if (implementingType == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } if (!typeof(Cmdlet).IsAssignableFrom(implementingType)) @@ -123,7 +123,7 @@ public CmdletInfo(string name, Type implementingType) { throw PSTraceSource.NewArgumentException( - "name", + nameof(name), DiscoveryExceptions.InvalidCmdletNameFormat, name); } diff --git a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs index 72d6ba964d4..069201589af 100644 --- a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs +++ b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs @@ -54,12 +54,12 @@ internal CmdletParameterBinderController( { if (cmdlet == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdlet)); } if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetadata"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } this.Command = cmdlet; @@ -4275,7 +4275,7 @@ private void RestoreDefaultParameterValues(IEnumerable MapStringInputToParsedInput(s { if (cursorIndex > input.Length) { - throw PSTraceSource.NewArgumentException("cursorIndex"); + throw PSTraceSource.NewArgumentException(nameof(cursorIndex)); } Token[] tokens; @@ -112,17 +112,17 @@ public static CommandCompletion CompleteInput(Ast ast, Token[] tokens, IScriptPo { if (ast == null) { - throw PSTraceSource.NewArgumentNullException("ast"); + throw PSTraceSource.NewArgumentNullException(nameof(ast)); } if (tokens == null) { - throw PSTraceSource.NewArgumentNullException("tokens"); + throw PSTraceSource.NewArgumentNullException(nameof(tokens)); } if (positionOfCursor == null) { - throw PSTraceSource.NewArgumentNullException("positionOfCursor"); + throw PSTraceSource.NewArgumentNullException(nameof(positionOfCursor)); } return CompleteInputImpl(ast, tokens, positionOfCursor, options); @@ -147,12 +147,12 @@ public static CommandCompletion CompleteInput(string input, int cursorIndex, Has if (cursorIndex > input.Length) { - throw PSTraceSource.NewArgumentException("cursorIndex"); + throw PSTraceSource.NewArgumentException(nameof(cursorIndex)); } if (powershell == null) { - throw PSTraceSource.NewArgumentNullException("powershell"); + throw PSTraceSource.NewArgumentNullException(nameof(powershell)); } // If we are in a debugger stop, let the debugger do the command completion. @@ -216,22 +216,22 @@ public static CommandCompletion CompleteInput(Ast ast, Token[] tokens, IScriptPo { if (ast == null) { - throw PSTraceSource.NewArgumentNullException("ast"); + throw PSTraceSource.NewArgumentNullException(nameof(ast)); } if (tokens == null) { - throw PSTraceSource.NewArgumentNullException("tokens"); + throw PSTraceSource.NewArgumentNullException(nameof(tokens)); } if (cursorPosition == null) { - throw PSTraceSource.NewArgumentNullException("cursorPosition"); + throw PSTraceSource.NewArgumentNullException(nameof(cursorPosition)); } if (powershell == null) { - throw PSTraceSource.NewArgumentNullException("powershell"); + throw PSTraceSource.NewArgumentNullException(nameof(powershell)); } // If we are in a debugger stop, let the debugger do the command completion. @@ -334,12 +334,12 @@ internal static CommandCompletion CompleteInputInDebugger(string input, int curs if (cursorIndex > input.Length) { - throw PSTraceSource.NewArgumentException("cursorIndex"); + throw PSTraceSource.NewArgumentException(nameof(cursorIndex)); } if (debugger == null) { - throw PSTraceSource.NewArgumentNullException("debugger"); + throw PSTraceSource.NewArgumentNullException(nameof(debugger)); } Command cmd = new Command("TabExpansion2"); @@ -363,22 +363,22 @@ internal static CommandCompletion CompleteInputInDebugger(Ast ast, Token[] token { if (ast == null) { - throw PSTraceSource.NewArgumentNullException("ast"); + throw PSTraceSource.NewArgumentNullException(nameof(ast)); } if (tokens == null) { - throw PSTraceSource.NewArgumentNullException("tokens"); + throw PSTraceSource.NewArgumentNullException(nameof(tokens)); } if (cursorPosition == null) { - throw PSTraceSource.NewArgumentNullException("cursorPosition"); + throw PSTraceSource.NewArgumentNullException(nameof(cursorPosition)); } if (debugger == null) { - throw PSTraceSource.NewArgumentNullException("debugger"); + throw PSTraceSource.NewArgumentNullException(nameof(debugger)); } // For remote debugging just pass string input. diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 70027d06c43..7ff17435001 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -207,7 +207,7 @@ List ExecuteGetCommandCommand(bool useModulePrefix) } private static readonly HashSet s_keywordsToExcludeFromAddingAmpersand - = new HashSet(StringComparer.OrdinalIgnoreCase) { TokenKind.InlineScript.ToString(), TokenKind.Configuration.ToString() }; + = new HashSet(StringComparer.OrdinalIgnoreCase) { nameof(TokenKind.InlineScript), nameof(TokenKind.Configuration) }; internal static CompletionResult GetCommandNameCompletionResult(string name, object command, bool addAmpersandIfNecessary, string quote) { string syntax = name, listItem = name; diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionResult.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionResult.cs index 763f54b60fa..3fe4a54e023 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionResult.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionResult.cs @@ -170,22 +170,22 @@ public CompletionResult(string completionText, string listItemText, CompletionRe { if (string.IsNullOrEmpty(completionText)) { - throw PSTraceSource.NewArgumentNullException("completionText"); + throw PSTraceSource.NewArgumentNullException(nameof(completionText)); } if (string.IsNullOrEmpty(listItemText)) { - throw PSTraceSource.NewArgumentNullException("listItemText"); + throw PSTraceSource.NewArgumentNullException(nameof(listItemText)); } if (resultType < CompletionResultType.Text || resultType > CompletionResultType.DynamicKeyword) { - throw PSTraceSource.NewArgumentOutOfRangeException("resultType", resultType); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(resultType), resultType); } if (string.IsNullOrEmpty(toolTip)) { - throw PSTraceSource.NewArgumentNullException("toolTip"); + throw PSTraceSource.NewArgumentNullException(nameof(toolTip)); } _completionText = completionText; diff --git a/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs index 71c76b3ce67..9bb33ef56ba 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs @@ -34,7 +34,7 @@ public ArgumentCompleterAttribute(Type type) { if (type == null || (type.GetInterfaces().All(t => t != typeof(IArgumentCompleter)))) { - throw PSTraceSource.NewArgumentException("type"); + throw PSTraceSource.NewArgumentException(nameof(type)); } Type = type; @@ -48,7 +48,7 @@ public ArgumentCompleterAttribute(ScriptBlock scriptBlock) { if (scriptBlock == null) { - throw PSTraceSource.NewArgumentNullException("scriptBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock)); } ScriptBlock = scriptBlock; @@ -176,12 +176,12 @@ public ArgumentCompletionsAttribute(params string[] completions) { if (completions == null) { - throw PSTraceSource.NewArgumentNullException("completions"); + throw PSTraceSource.NewArgumentNullException(nameof(completions)); } if (completions.Length == 0) { - throw PSTraceSource.NewArgumentOutOfRangeException("completions", completions); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(completions), completions); } _completions = completions; diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index 2b10b988ea6..b8ed6df5042 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -75,7 +75,7 @@ internal sealed class PipeObjectPair : AstParameterArgumentPair internal PipeObjectPair(string parameterName, Type pipeObjType) { if (parameterName == null) - throw PSTraceSource.NewArgumentNullException("parameterName"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterName)); Parameter = null; ParameterArgumentType = AstParameterArgumentType.PipeObject; @@ -96,9 +96,9 @@ internal sealed class AstArrayPair : AstParameterArgumentPair internal AstArrayPair(string parameterName, ICollection arguments) { if (parameterName == null) - throw PSTraceSource.NewArgumentNullException("parameterName"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterName)); if (arguments == null || arguments.Count == 0) - throw PSTraceSource.NewArgumentNullException("arguments"); + throw PSTraceSource.NewArgumentNullException(nameof(arguments)); Parameter = null; ParameterArgumentType = AstParameterArgumentType.AstArray; @@ -125,7 +125,7 @@ internal sealed class FakePair : AstParameterArgumentPair internal FakePair(CommandParameterAst parameterAst) { if (parameterAst == null) - throw PSTraceSource.NewArgumentNullException("parameterAst"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterAst)); Parameter = parameterAst; ParameterArgumentType = AstParameterArgumentType.Fake; @@ -145,7 +145,7 @@ internal sealed class SwitchPair : AstParameterArgumentPair internal SwitchPair(CommandParameterAst parameterAst) { if (parameterAst == null) - throw PSTraceSource.NewArgumentNullException("parameterAst"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterAst)); Parameter = parameterAst; ParameterArgumentType = AstParameterArgumentType.Switch; @@ -175,7 +175,7 @@ internal sealed class AstPair : AstParameterArgumentPair internal AstPair(CommandParameterAst parameterAst) { if (parameterAst == null || parameterAst.Argument == null) - throw PSTraceSource.NewArgumentException("parameterAst"); + throw PSTraceSource.NewArgumentException(nameof(parameterAst)); Parameter = parameterAst; ParameterArgumentType = AstParameterArgumentType.AstPair; @@ -192,10 +192,10 @@ internal AstPair(CommandParameterAst parameterAst) internal AstPair(CommandParameterAst parameterAst, ExpressionAst argumentAst) { if (parameterAst != null && parameterAst.Argument != null) - throw PSTraceSource.NewArgumentException("parameterAst"); + throw PSTraceSource.NewArgumentException(nameof(parameterAst)); if (parameterAst == null && argumentAst == null) - throw PSTraceSource.NewArgumentNullException("argumentAst"); + throw PSTraceSource.NewArgumentNullException(nameof(argumentAst)); Parameter = parameterAst; ParameterArgumentType = AstParameterArgumentType.AstPair; @@ -212,10 +212,10 @@ internal AstPair(CommandParameterAst parameterAst, ExpressionAst argumentAst) internal AstPair(CommandParameterAst parameterAst, CommandElementAst argumentAst) { if (parameterAst != null && parameterAst.Argument != null) - throw PSTraceSource.NewArgumentException("parameterAst"); + throw PSTraceSource.NewArgumentException(nameof(parameterAst)); if (parameterAst == null || argumentAst == null) - throw PSTraceSource.NewArgumentNullException("argumentAst"); + throw PSTraceSource.NewArgumentNullException(nameof(argumentAst)); Parameter = parameterAst; ParameterArgumentType = AstParameterArgumentType.AstPair; @@ -949,7 +949,7 @@ internal PseudoBindingInfo DoPseudoParameterBinding(CommandAst command, Type pip { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } // initialize/reset the private members diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index c194a2f40f6..4b58da58cb6 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -133,7 +133,7 @@ internal CommandDiscovery(ExecutionContext context) { if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } Context = context; @@ -202,7 +202,7 @@ internal CmdletInfo AddCmdletInfoToCache(string name, CmdletInfo newCmdletInfo, { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (newCmdletInfo == null) @@ -1525,7 +1525,7 @@ internal static PSModuleAutoLoadingPreference GetCommandDiscoveryPreference(Exec if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } // check the PSVariable @@ -1687,7 +1687,7 @@ internal Collection IndexOfRelativePath() { if (string.IsNullOrEmpty(item)) { - throw PSTraceSource.NewArgumentException("item"); + throw PSTraceSource.NewArgumentException(nameof(item)); } int result = -1; diff --git a/src/System.Management.Automation/engine/CommandInfo.cs b/src/System.Management.Automation/engine/CommandInfo.cs index e55240a4cfa..1090a3fbb86 100644 --- a/src/System.Management.Automation/engine/CommandInfo.cs +++ b/src/System.Management.Automation/engine/CommandInfo.cs @@ -112,7 +112,7 @@ internal CommandInfo(string name, CommandTypes type) if (name == null) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } Name = name; @@ -287,7 +287,7 @@ internal void Rename(string newName) { if (string.IsNullOrEmpty(newName)) { - throw new ArgumentNullException("newName"); + throw new ArgumentNullException(nameof(newName)); } Name = newName; @@ -800,7 +800,7 @@ public PSTypeName(TypeDefinitionAst typeDefinitionAst) { if (typeDefinitionAst == null) { - throw PSTraceSource.NewArgumentNullException("typeDefinitionAst"); + throw PSTraceSource.NewArgumentNullException(nameof(typeDefinitionAst)); } TypeDefinitionAst = typeDefinitionAst; @@ -814,7 +814,7 @@ public PSTypeName(ITypeName typeName) { if (typeName == null) { - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); } _type = typeName.GetReflectionType(); diff --git a/src/System.Management.Automation/engine/CommandMetadata.cs b/src/System.Management.Automation/engine/CommandMetadata.cs index 02f4f23c3cc..5ad657b037f 100644 --- a/src/System.Management.Automation/engine/CommandMetadata.cs +++ b/src/System.Management.Automation/engine/CommandMetadata.cs @@ -105,7 +105,7 @@ public CommandMetadata(CommandInfo commandInfo, bool shouldGenerateCommonParamet { if (commandInfo == null) { - throw PSTraceSource.NewArgumentNullException("commandInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(commandInfo)); } while (commandInfo is AliasInfo) { @@ -162,7 +162,7 @@ public CommandMetadata(CommandMetadata other) { if (other == null) { - throw PSTraceSource.NewArgumentNullException("other"); + throw PSTraceSource.NewArgumentNullException(nameof(other)); } Name = other.Name; @@ -315,7 +315,7 @@ internal static CommandMetadata Get(string commandName, Type cmdletType, Executi { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentException("commandName"); + throw PSTraceSource.NewArgumentException(nameof(commandName)); } CommandMetadata result = null; @@ -369,7 +369,7 @@ internal CommandMetadata(string commandName, Type cmdletType, ExecutionContext c { if (string.IsNullOrEmpty(commandName)) { - throw PSTraceSource.NewArgumentException("commandName"); + throw PSTraceSource.NewArgumentException(nameof(commandName)); } Name = commandName; @@ -412,7 +412,7 @@ internal CommandMetadata(ScriptBlock scriptblock, string commandName, ExecutionC { if (scriptblock == null) { - throw PSTraceSource.NewArgumentException("scriptblock"); + throw PSTraceSource.NewArgumentException(nameof(scriptblock)); } CmdletBindingAttribute cmdletBindingAttribute = scriptblock.CmdletBindingAttribute; @@ -725,7 +725,7 @@ private void ProcessCmdletAttribute(CmdletCommonMetadataAttribute attribute) { if (attribute == null) { - throw PSTraceSource.NewArgumentNullException("attribute"); + throw PSTraceSource.NewArgumentNullException(nameof(attribute)); } // Process the default parameter set name diff --git a/src/System.Management.Automation/engine/CommandProcessor.cs b/src/System.Management.Automation/engine/CommandProcessor.cs index e7454b112a7..48abebc7a17 100644 --- a/src/System.Management.Automation/engine/CommandProcessor.cs +++ b/src/System.Management.Automation/engine/CommandProcessor.cs @@ -104,7 +104,7 @@ internal ParameterBinderController NewParameterBinderController(InternalCommand Cmdlet cmdlet = command as Cmdlet; if (cmdlet == null) { - throw PSTraceSource.NewArgumentException("command"); + throw PSTraceSource.NewArgumentException(nameof(command)); } ParameterBinderBase parameterBinder; diff --git a/src/System.Management.Automation/engine/CommandProcessorBase.cs b/src/System.Management.Automation/engine/CommandProcessorBase.cs index 8a01dc34980..e2c8ad46e5c 100644 --- a/src/System.Management.Automation/engine/CommandProcessorBase.cs +++ b/src/System.Management.Automation/engine/CommandProcessorBase.cs @@ -35,7 +35,7 @@ internal CommandProcessorBase(CommandInfo commandInfo) { if (commandInfo == null) { - throw PSTraceSource.NewArgumentNullException("commandInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(commandInfo)); } if (commandInfo is IScriptCommandInfo scriptCommand) @@ -278,12 +278,12 @@ internal static CommandProcessorBase CreateGetHelpCommandProcessor( { if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } if (string.IsNullOrEmpty(helpTarget)) { - throw PSTraceSource.NewArgumentNullException("helpTarget"); + throw PSTraceSource.NewArgumentNullException(nameof(helpTarget)); } CommandProcessorBase helpCommandProcessor = context.CreateCommand("get-help", false); diff --git a/src/System.Management.Automation/engine/CommonCommandParameters.cs b/src/System.Management.Automation/engine/CommonCommandParameters.cs index 19c693551a2..9cc0b2ad899 100644 --- a/src/System.Management.Automation/engine/CommonCommandParameters.cs +++ b/src/System.Management.Automation/engine/CommonCommandParameters.cs @@ -28,7 +28,7 @@ internal CommonParameters(MshCommandRuntime commandRuntime) { if (commandRuntime == null) { - throw PSTraceSource.NewArgumentNullException("commandRuntime"); + throw PSTraceSource.NewArgumentNullException(nameof(commandRuntime)); } _commandRuntime = commandRuntime; diff --git a/src/System.Management.Automation/engine/CompiledCommandParameter.cs b/src/System.Management.Automation/engine/CompiledCommandParameter.cs index 48a7b2fd415..a9e85f43280 100644 --- a/src/System.Management.Automation/engine/CompiledCommandParameter.cs +++ b/src/System.Management.Automation/engine/CompiledCommandParameter.cs @@ -37,7 +37,7 @@ internal CompiledCommandParameter(RuntimeDefinedParameter runtimeDefinedParamete { if (runtimeDefinedParameter == null) { - throw PSTraceSource.NewArgumentNullException("runtimeDefinedParameter"); + throw PSTraceSource.NewArgumentNullException(nameof(runtimeDefinedParameter)); } this.Name = runtimeDefinedParameter.Name; @@ -123,7 +123,7 @@ internal CompiledCommandParameter(MemberInfo member, bool processingDynamicParam { if (member == null) { - throw PSTraceSource.NewArgumentNullException("member"); + throw PSTraceSource.NewArgumentNullException(nameof(member)); } this.Name = member.Name; @@ -146,7 +146,7 @@ internal CompiledCommandParameter(MemberInfo member, bool processingDynamicParam { ArgumentException e = PSTraceSource.NewArgumentException( - "member", + nameof(member), DiscoveryExceptions.CompiledCommandParameterMemberMustBeFieldOrProperty); throw e; diff --git a/src/System.Management.Automation/engine/ContentCmdletProviderInterfaces.cs b/src/System.Management.Automation/engine/ContentCmdletProviderInterfaces.cs index a2997a77b72..382f6b7e46a 100644 --- a/src/System.Management.Automation/engine/ContentCmdletProviderInterfaces.cs +++ b/src/System.Management.Automation/engine/ContentCmdletProviderInterfaces.cs @@ -39,7 +39,7 @@ internal ContentCmdletProviderIntrinsics(Cmdlet cmdlet) { if (cmdlet == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdlet)); } _cmdlet = cmdlet; @@ -59,7 +59,7 @@ internal ContentCmdletProviderIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/CoreAdapter.cs b/src/System.Management.Automation/engine/CoreAdapter.cs index 6bf9d0c52aa..44361ffa04f 100644 --- a/src/System.Management.Automation/engine/CoreAdapter.cs +++ b/src/System.Management.Automation/engine/CoreAdapter.cs @@ -1856,7 +1856,7 @@ internal static object MethodArgumentConvertTo(object valueToConvert, { if (resultType == null) { - throw PSTraceSource.NewArgumentNullException("resultType"); + throw PSTraceSource.NewArgumentNullException(nameof(resultType)); } bool isArgumentByRef; @@ -1911,7 +1911,7 @@ internal static object PropertySetAndMethodArgumentConvertTo(object valueToConve { if (resultType == null) { - throw PSTraceSource.NewArgumentNullException("resultType"); + throw PSTraceSource.NewArgumentNullException(nameof(resultType)); } PSObject mshObj = valueToConvert as PSObject; diff --git a/src/System.Management.Automation/engine/Credential.cs b/src/System.Management.Automation/engine/Credential.cs index df17c38a884..6b9c4be8d4d 100644 --- a/src/System.Management.Automation/engine/Credential.cs +++ b/src/System.Management.Automation/engine/Credential.cs @@ -219,7 +219,7 @@ public PSCredential(string userName, SecureString password) public PSCredential(PSObject pso) { if (pso == null) - throw PSTraceSource.NewArgumentNullException("pso"); + throw PSTraceSource.NewArgumentNullException(nameof(pso)); if (pso.Properties["UserName"] != null) { diff --git a/src/System.Management.Automation/engine/DataStoreAdapter.cs b/src/System.Management.Automation/engine/DataStoreAdapter.cs index 3b01bae2934..6b9a77f45f7 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapter.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapter.cs @@ -127,7 +127,7 @@ internal void SetRoot(string path) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (!DriveBeingCreated) @@ -271,7 +271,7 @@ protected PSDriveInfo(PSDriveInfo driveInfo) { if (driveInfo == null) { - throw PSTraceSource.NewArgumentNullException("driveInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(driveInfo)); } _name = driveInfo.Name; @@ -326,17 +326,17 @@ public PSDriveInfo( if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } if (root == null) { - throw PSTraceSource.NewArgumentNullException("root"); + throw PSTraceSource.NewArgumentNullException(nameof(root)); } // Copy the parameters to the local members @@ -508,7 +508,7 @@ internal void SetName(string newName) { if (string.IsNullOrEmpty(newName)) { - throw PSTraceSource.NewArgumentException("newName"); + throw PSTraceSource.NewArgumentException(nameof(newName)); } _name = newName; @@ -534,7 +534,7 @@ internal void SetProvider(ProviderInfo newProvider) { if (newProvider == null) { - throw PSTraceSource.NewArgumentNullException("newProvider"); + throw PSTraceSource.NewArgumentNullException(nameof(newProvider)); } _provider = newProvider; @@ -602,7 +602,7 @@ public int CompareTo(PSDriveInfo drive) if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } return string.Compare(Name, drive.Name, StringComparison.OrdinalIgnoreCase); @@ -631,7 +631,7 @@ public int CompareTo(object obj) { ArgumentException e = PSTraceSource.NewArgumentException( - "obj", + nameof(obj), SessionStateStrings.OnlyAbleToComparePSDriveInfo); throw e; } diff --git a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs index d341b2803dd..cfc7528b90b 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs @@ -297,7 +297,7 @@ protected ProviderInfo(ProviderInfo providerInfo) { if (providerInfo == null) { - throw PSTraceSource.NewArgumentNullException("providerInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInfo)); } Name = providerInfo.Name; @@ -394,17 +394,17 @@ internal ProviderInfo( // Verify parameters if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } if (implementingType == null) { - throw PSTraceSource.NewArgumentNullException("implementingType"); + throw PSTraceSource.NewArgumentNullException(nameof(implementingType)); } if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/DefaultCommandRuntime.cs b/src/System.Management.Automation/engine/DefaultCommandRuntime.cs index 4df5c39fe15..b4f21bb5c26 100644 --- a/src/System.Management.Automation/engine/DefaultCommandRuntime.cs +++ b/src/System.Management.Automation/engine/DefaultCommandRuntime.cs @@ -21,7 +21,7 @@ internal class DefaultCommandRuntime : ICommandRuntime2 public DefaultCommandRuntime(List outputList) { if (outputList == null) - throw new System.ArgumentNullException("outputList"); + throw new System.ArgumentNullException(nameof(outputList)); _output = outputList; } diff --git a/src/System.Management.Automation/engine/DriveInterfaces.cs b/src/System.Management.Automation/engine/DriveInterfaces.cs index 8d605e7313a..36bfc73c573 100644 --- a/src/System.Management.Automation/engine/DriveInterfaces.cs +++ b/src/System.Management.Automation/engine/DriveInterfaces.cs @@ -38,7 +38,7 @@ internal DriveManagementIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/EngineIntrinsics.cs b/src/System.Management.Automation/engine/EngineIntrinsics.cs index ca322dbff06..d0bc7a2f100 100644 --- a/src/System.Management.Automation/engine/EngineIntrinsics.cs +++ b/src/System.Management.Automation/engine/EngineIntrinsics.cs @@ -37,7 +37,7 @@ internal EngineIntrinsics(ExecutionContext context) { if (context == null) { - throw new ArgumentNullException("context"); + throw new ArgumentNullException(nameof(context)); } _context = context; diff --git a/src/System.Management.Automation/engine/ErrorPackage.cs b/src/System.Management.Automation/engine/ErrorPackage.cs index cf02b7db8d1..1f308dc2ecd 100644 --- a/src/System.Management.Automation/engine/ErrorPackage.cs +++ b/src/System.Management.Automation/engine/ErrorPackage.cs @@ -420,7 +420,7 @@ public string GetMessage(CultureInfo uiCultureInfo) if (string.IsNullOrEmpty(errorCategoryString)) { // this probably indicates an invalid ErrorCategory value - errorCategoryString = ErrorCategory.NotSpecified.ToString(); + errorCategoryString = nameof(ErrorCategory.NotSpecified); } string templateText = ErrorCategoryStrings.ResourceManager.GetString(errorCategoryString, uiCultureInfo); diff --git a/src/System.Management.Automation/engine/EventManager.cs b/src/System.Management.Automation/engine/EventManager.cs index 86c639ab9af..c524e3646c5 100644 --- a/src/System.Management.Automation/engine/EventManager.cs +++ b/src/System.Management.Automation/engine/EventManager.cs @@ -666,7 +666,7 @@ private void ProcessNewSubscriber(PSEventSubscriber subscriber, object source, s { string errorMessage = StringUtil.Format(EventingResources.ReservedIdentifier, sourceIdentifier); - throw new ArgumentException(errorMessage, "sourceIdentifier"); + throw new ArgumentException(errorMessage, nameof(sourceIdentifier)); } EventInfo eventInfo = null; @@ -686,7 +686,7 @@ private void ProcessNewSubscriber(PSEventSubscriber subscriber, object source, s if (eventInfo == null) { string errorMessage = StringUtil.Format(EventingResources.CouldNotFindEvent, eventName); - throw new ArgumentException(errorMessage, "eventName"); + throw new ArgumentException(errorMessage, nameof(eventName)); } // Try to set the EnableRaisingEvents property if it defines one @@ -722,7 +722,7 @@ private void ProcessNewSubscriber(PSEventSubscriber subscriber, object source, s if (invokeMethod.ReturnType != typeof(void)) { string errorMessage = EventingResources.NonVoidDelegateNotSupported; - throw new ArgumentException(errorMessage, "eventName"); + throw new ArgumentException(errorMessage, nameof(eventName)); } // Cache generated event handlers (by type and event name) so that they don't bloat our @@ -818,7 +818,7 @@ private void UnsubscribeEvent(PSEventSubscriber subscriber, bool skipDraining) { if (subscriber == null) { - throw new ArgumentNullException("subscriber"); + throw new ArgumentNullException(nameof(subscriber)); } Delegate existingSubscriber = null; @@ -2362,7 +2362,7 @@ internal void Add(PSEventArgs eventToAdd) { if (eventToAdd == null) { - throw new ArgumentNullException("eventToAdd"); + throw new ArgumentNullException(nameof(eventToAdd)); } _eventCollection.Add(eventToAdd); @@ -2479,9 +2479,9 @@ public PSEventJob(PSEventManager eventManager, PSEventSubscriber subscriber, Scr base(action == null ? null : action.ToString(), name) { if (eventManager == null) - throw new ArgumentNullException("eventManager"); + throw new ArgumentNullException(nameof(eventManager)); if (subscriber == null) - throw new ArgumentNullException("subscriber"); + throw new ArgumentNullException(nameof(subscriber)); UsesResultsCollection = true; ScriptBlock = action; diff --git a/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs b/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs index 9337f48542b..f6993a03a0a 100644 --- a/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs +++ b/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs @@ -349,7 +349,7 @@ internal static void ValidateArguments(string experimentName, ExperimentAction e if (experimentAction == ExperimentAction.None) { string paramName = nameof(experimentAction); - string invalidMember = ExperimentAction.None.ToString(); + string invalidMember = nameof(ExperimentAction.None); string validMembers = StringUtil.Format("{0}, {1}", ExperimentAction.Hide, ExperimentAction.Show); throw PSTraceSource.NewArgumentException(paramName, Metadata.InvalidEnumArgument, invalidMember, paramName, validMembers); } diff --git a/src/System.Management.Automation/engine/ExtendedTypeSystemException.cs b/src/System.Management.Automation/engine/ExtendedTypeSystemException.cs index 4866316efdc..542ad8bbf7e 100644 --- a/src/System.Management.Automation/engine/ExtendedTypeSystemException.cs +++ b/src/System.Management.Automation/engine/ExtendedTypeSystemException.cs @@ -532,7 +532,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/engine/ExternalScriptInfo.cs b/src/System.Management.Automation/engine/ExternalScriptInfo.cs index ef4bc477653..d87e3027f2e 100644 --- a/src/System.Management.Automation/engine/ExternalScriptInfo.cs +++ b/src/System.Management.Automation/engine/ExternalScriptInfo.cs @@ -44,7 +44,7 @@ internal ExternalScriptInfo(string name, string path, ExecutionContext context) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } Diagnostics.Assert(IO.Path.IsPathRooted(path), "Caller makes sure that 'path' is already resolved."); @@ -71,7 +71,7 @@ internal ExternalScriptInfo(string name, string path) : base(name, CommandTypes. { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } Diagnostics.Assert(IO.Path.IsPathRooted(path), "Caller makes sure that 'path' is already resolved."); diff --git a/src/System.Management.Automation/engine/FunctionInfo.cs b/src/System.Management.Automation/engine/FunctionInfo.cs index 95bdf5b0025..8afe41ece15 100644 --- a/src/System.Management.Automation/engine/FunctionInfo.cs +++ b/src/System.Management.Automation/engine/FunctionInfo.cs @@ -55,7 +55,7 @@ internal FunctionInfo(string name, ScriptBlock function, ExecutionContext contex { if (function == null) { - throw PSTraceSource.NewArgumentNullException("function"); + throw PSTraceSource.NewArgumentNullException(nameof(function)); } _scriptBlock = function; diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index 709c84b973c..adc7c9c95bd 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -1660,7 +1660,7 @@ public IEnumerable CompleteArgument(string commandName, string { if (fakeBoundParameters == null) { - throw PSTraceSource.NewArgumentNullException("fakeBoundParameters"); + throw PSTraceSource.NewArgumentNullException(nameof(fakeBoundParameters)); } var commandInfo = new CmdletInfo("Get-Command", typeof(GetCommandCommand)); diff --git a/src/System.Management.Automation/engine/ItemCmdletProviderInterfaces.cs b/src/System.Management.Automation/engine/ItemCmdletProviderInterfaces.cs index 63f4bbaffcb..699d60dafa0 100644 --- a/src/System.Management.Automation/engine/ItemCmdletProviderInterfaces.cs +++ b/src/System.Management.Automation/engine/ItemCmdletProviderInterfaces.cs @@ -38,7 +38,7 @@ internal ItemCmdletProviderIntrinsics(Cmdlet cmdlet) { if (cmdlet == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdlet)); } _cmdlet = cmdlet; @@ -58,7 +58,7 @@ internal ItemCmdletProviderIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 50b2e7950f7..039761b4118 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -639,7 +639,7 @@ public static bool Equals(object first, object second, bool ignoreCase, IFormatP var culture = formatProvider as CultureInfo; if (culture == null) { - throw PSTraceSource.NewArgumentException("formatProvider"); + throw PSTraceSource.NewArgumentException(nameof(formatProvider)); } first = PSObject.Base(first); @@ -787,7 +787,7 @@ public static int Compare(object first, object second, bool ignoreCase, IFormatP var culture = formatProvider as CultureInfo; if (culture == null) { - throw PSTraceSource.NewArgumentException("formatProvider"); + throw PSTraceSource.NewArgumentException(nameof(formatProvider)); } first = PSObject.Base(first); @@ -814,7 +814,7 @@ public static int Compare(object first, object second, bool ignoreCase, IFormatP } catch (PSInvalidCastException e) { - throw PSTraceSource.NewArgumentException("second", ExtendedTypeSystem.ComparisonFailure, + throw PSTraceSource.NewArgumentException(nameof(second), ExtendedTypeSystem.ComparisonFailure, first.ToString(), second.ToString(), e.Message); } } @@ -839,7 +839,7 @@ public static int Compare(object first, object second, bool ignoreCase, IFormatP } catch (PSInvalidCastException e) { - throw PSTraceSource.NewArgumentException("second", ExtendedTypeSystem.ComparisonFailure, + throw PSTraceSource.NewArgumentException(nameof(second), ExtendedTypeSystem.ComparisonFailure, first.ToString(), second.ToString(), e.Message); } @@ -855,7 +855,7 @@ public static int Compare(object first, object second, bool ignoreCase, IFormatP // At this point, we know that they aren't equal but we have no way of // knowing which should compare greater than the other so we throw an exception. - throw PSTraceSource.NewArgumentException("first", ExtendedTypeSystem.NotIcomparable, first.ToString()); + throw PSTraceSource.NewArgumentException(nameof(first), ExtendedTypeSystem.NotIcomparable, first.ToString()); } /// @@ -907,7 +907,7 @@ public static bool TryCompare(object first, object second, bool ignoreCase, IFor if (!(formatProvider is CultureInfo culture)) { - throw PSTraceSource.NewArgumentException("formatProvider"); + throw PSTraceSource.NewArgumentException(nameof(formatProvider)); } first = PSObject.Base(first); @@ -4788,7 +4788,7 @@ internal static object ConvertTo(object valueToConvert, { if (resultType == null) { - throw PSTraceSource.NewArgumentNullException("resultType"); + throw PSTraceSource.NewArgumentNullException(nameof(resultType)); } bool debase; diff --git a/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs b/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs index 8bb14cebccb..9efd502badb 100644 --- a/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs +++ b/src/System.Management.Automation/engine/MergedCommandParameterMetadata.cs @@ -81,7 +81,7 @@ internal Collection AddMetadataForBinder( { if (parameterMetadata == null) { - throw PSTraceSource.NewArgumentNullException("parameterMetadata"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterMetadata)); } Collection result = @@ -443,7 +443,7 @@ internal MergedCompiledCommandParameter GetMatchingParameter( { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } Collection matchingParameters = diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index a4b30616132..0e821686f53 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -7148,7 +7148,7 @@ internal static void ImportModuleMembers( ImportModuleOptions options) { if (sourceModule == null) - throw PSTraceSource.NewArgumentNullException("sourceModule"); + throw PSTraceSource.NewArgumentNullException(nameof(sourceModule)); bool isImportModulePrivate = cmdlet.CommandInfo.Visibility == SessionStateEntryVisibility.Private || targetSessionState.DefaultCommandVisibility == SessionStateEntryVisibility.Private; diff --git a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs index 29bc54a6798..af0b93567b6 100644 --- a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs +++ b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs @@ -130,7 +130,7 @@ public PSModuleInfo(ScriptBlock scriptBlock) { if (scriptBlock == null) { - throw PSTraceSource.NewArgumentException("scriptBlock"); + throw PSTraceSource.NewArgumentException(nameof(scriptBlock)); } // Get the ExecutionContext from the thread. @@ -1305,7 +1305,7 @@ public PSVariable GetVariableFromCallersModule(string variableName) { if (string.IsNullOrEmpty(variableName)) { - throw new ArgumentNullException("variableName"); + throw new ArgumentNullException(nameof(variableName)); } var context = LocalPipeline.GetExecutionContextFromTLS(); diff --git a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs index 10f53ef0136..fce9c2e58c8 100644 --- a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs +++ b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs @@ -970,7 +970,7 @@ private static CimCredential GetCimCredentials(string authentication, PSCredenti } Dbg.Assert(false, "Unrecognized authentication mechanism [ValidateSet should prevent that from happening]"); - throw new ArgumentOutOfRangeException("authentication"); + throw new ArgumentOutOfRangeException(nameof(authentication)); } internal static CimSession CreateCimSession( diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs index 839ea1c005f..d6c8d941a04 100644 --- a/src/System.Management.Automation/engine/MshCmdlet.cs +++ b/src/System.Management.Automation/engine/MshCmdlet.cs @@ -435,7 +435,7 @@ public CmdletInfo GetCmdletByTypeName(string cmdletTypeName) { if (string.IsNullOrEmpty(cmdletTypeName)) { - throw PSTraceSource.NewArgumentNullException("cmdletTypeName"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdletTypeName)); } Exception e = null; @@ -486,7 +486,7 @@ public List GetCmdlets() public List GetCmdlets(string pattern) { if (pattern == null) - throw PSTraceSource.NewArgumentNullException("pattern"); + throw PSTraceSource.NewArgumentNullException(nameof(pattern)); List cmdlets = new List(); @@ -548,7 +548,7 @@ public List GetCommandName(string name, bool nameIsPattern, bool returnF { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } List commands = new List(); @@ -608,7 +608,7 @@ public IEnumerable GetCommands(string name, CommandTypes commandTyp { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } SearchResolutionOptions options = nameIsPattern ? @@ -707,12 +707,12 @@ public Collection InvokeScript( { if (scriptBlock == null) { - throw PSTraceSource.NewArgumentNullException("scriptBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock)); } if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } SessionStateInternal _oldSessionState = _context.EngineSessionState; @@ -745,7 +745,7 @@ public Collection InvokeScript( { if (scriptBlock == null) { - throw PSTraceSource.NewArgumentNullException("scriptBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock)); } // Force the current runspace onto the callers thread - this is needed @@ -784,7 +784,7 @@ public Collection InvokeScript(string script, bool useNewScope, PipelineResultTypes writeToPipeline, IList input, params object[] args) { if (script == null) - throw new ArgumentNullException("script"); + throw new ArgumentNullException(nameof(script)); // Compile the script text into an executable script block. ScriptBlock sb = ScriptBlock.Create(_context, script); diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index a40ebced867..27c3af3fc60 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -396,7 +396,7 @@ internal void WriteProgress( { if (progressRecord == null) { - throw PSTraceSource.NewArgumentNullException("progressRecord"); + throw PSTraceSource.NewArgumentNullException(nameof(progressRecord)); } if (Host == null || Host.UI == null) @@ -2053,7 +2053,7 @@ public void ThrowTerminatingError(ErrorRecord errorRecord) ThrowIfStopping(); if (errorRecord == null) { - throw PSTraceSource.NewArgumentNullException("errorRecord"); + throw PSTraceSource.NewArgumentNullException(nameof(errorRecord)); } errorRecord.SetInvocationInfo(MyInvocation); @@ -2318,7 +2318,7 @@ private class AllowWrite : IDisposable internal AllowWrite(InternalCommand permittedToWrite, bool permittedToWriteToPipeline) { if (permittedToWrite == null) - throw PSTraceSource.NewArgumentNullException("permittedToWrite"); + throw PSTraceSource.NewArgumentNullException(nameof(permittedToWrite)); MshCommandRuntime mcr = permittedToWrite.commandRuntime as MshCommandRuntime; if (mcr == null) throw PSTraceSource.NewArgumentNullException("permittedToWrite.CommandRuntime"); @@ -2368,7 +2368,7 @@ public void Dispose() public Exception ManageException(Exception e) { if (e == null) - throw PSTraceSource.NewArgumentNullException("e"); + throw PSTraceSource.NewArgumentNullException(nameof(e)); if (PipelineProcessor != null) { diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index e341d6d8dda..4079669d94b 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -228,7 +228,7 @@ protected void SetMemberName(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -375,13 +375,13 @@ public PSAliasProperty(string name, string referencedMemberName) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; if (string.IsNullOrEmpty(referencedMemberName)) { - throw PSTraceSource.NewArgumentException("referencedMemberName"); + throw PSTraceSource.NewArgumentException(nameof(referencedMemberName)); } ReferencedMemberName = referencedMemberName; @@ -400,13 +400,13 @@ public PSAliasProperty(string name, string referencedMemberName, Type conversion { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; if (string.IsNullOrEmpty(referencedMemberName)) { - throw PSTraceSource.NewArgumentException("referencedMemberName"); + throw PSTraceSource.NewArgumentException(nameof(referencedMemberName)); } ReferencedMemberName = referencedMemberName; @@ -772,7 +772,7 @@ internal PSCodeProperty(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -789,13 +789,13 @@ public PSCodeProperty(string name, MethodInfo getterCodeReference) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; if (getterCodeReference == null) { - throw PSTraceSource.NewArgumentNullException("getterCodeReference"); + throw PSTraceSource.NewArgumentNullException(nameof(getterCodeReference)); } SetGetter(getterCodeReference); @@ -818,7 +818,7 @@ public PSCodeProperty(string name, MethodInfo getterCodeReference, MethodInfo se { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -1075,7 +1075,7 @@ internal PSProperty(string name, Adapter adapter, object baseObject, object adap { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -1292,7 +1292,7 @@ public PSNoteProperty(string name, object value) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -1438,7 +1438,7 @@ public override string ToString() public PSVariableProperty(PSVariable variable) : base(variable?.Name, null) { - _variable = variable ?? throw PSTraceSource.NewArgumentException("variable"); + _variable = variable ?? throw PSTraceSource.NewArgumentException(nameof(variable)); } #region virtual implementation @@ -1665,12 +1665,12 @@ public PSScriptProperty(string name, ScriptBlock getterScript) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; - _getterScript = getterScript ?? throw PSTraceSource.NewArgumentNullException("getterScript"); + _getterScript = getterScript ?? throw PSTraceSource.NewArgumentNullException(nameof(getterScript)); } /// @@ -1685,7 +1685,7 @@ public PSScriptProperty(string name, ScriptBlock getterScript, ScriptBlock sette { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -1722,7 +1722,7 @@ internal PSScriptProperty(string name, string getterScript, string setterScript, { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -2156,7 +2156,7 @@ internal PSCodeMethod(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -2173,12 +2173,12 @@ public PSCodeMethod(string name, MethodInfo codeReference) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (codeReference == null) { - throw PSTraceSource.NewArgumentNullException("codeReference"); + throw PSTraceSource.NewArgumentNullException(nameof(codeReference)); } if (!CheckMethodInfo(codeReference)) @@ -2229,7 +2229,7 @@ public override object Invoke(params object[] arguments) { if (arguments == null) { - throw PSTraceSource.NewArgumentNullException("arguments"); + throw PSTraceSource.NewArgumentNullException(nameof(arguments)); } object[] newArguments = new object[arguments.Length + 1]; @@ -2326,12 +2326,12 @@ public PSScriptMethod(string name, ScriptBlock script) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; - _script = script ?? throw PSTraceSource.NewArgumentNullException("script"); + _script = script ?? throw PSTraceSource.NewArgumentNullException(nameof(script)); } /// @@ -2364,7 +2364,7 @@ public override object Invoke(params object[] arguments) { if (arguments == null) { - throw PSTraceSource.NewArgumentNullException("arguments"); + throw PSTraceSource.NewArgumentNullException(nameof(arguments)); } return InvokeScript(Name, _script, this.instance, arguments); @@ -2489,7 +2489,7 @@ internal PSMethod(string name, Adapter adapter, object baseObject, object adapte { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -2559,7 +2559,7 @@ internal object Invoke(PSMethodInvocationConstraints invocationConstraints, para { if (arguments == null) { - throw PSTraceSource.NewArgumentNullException("arguments"); + throw PSTraceSource.NewArgumentNullException(nameof(arguments)); } return _adapter.BaseMethodInvoke(this, invocationConstraints, arguments); @@ -2908,7 +2908,7 @@ internal PSParameterizedProperty(string name, Adapter adapter, object baseObject { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -2921,7 +2921,7 @@ internal PSParameterizedProperty(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; @@ -2950,7 +2950,7 @@ public override object Invoke(params object[] arguments) { if (arguments == null) { - throw PSTraceSource.NewArgumentNullException("arguments"); + throw PSTraceSource.NewArgumentNullException(nameof(arguments)); } return this.adapter.BaseParameterizedPropertyGet(this, arguments); @@ -2967,7 +2967,7 @@ public void InvokeSet(object valueToSet, params object[] arguments) { if (arguments == null) { - throw PSTraceSource.NewArgumentNullException("arguments"); + throw PSTraceSource.NewArgumentNullException(nameof(arguments)); } this.adapter.BaseParameterizedPropertySet(this, valueToSet, arguments); @@ -3172,13 +3172,13 @@ internal PSMemberSet(string name, PSObject mshObject) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } this.name = name; if (mshObject == null) { - throw PSTraceSource.NewArgumentNullException("mshObject"); + throw PSTraceSource.NewArgumentNullException(nameof(mshObject)); } _constructorPSObject = mshObject; @@ -3692,12 +3692,12 @@ internal static PSMemberInfoInternalCollection Match(PSMemberInfoInternalC PSMemberInfoInternalCollection returnValue = new PSMemberInfoInternalCollection(); if (memberList == null) { - throw PSTraceSource.NewArgumentNullException("memberList"); + throw PSTraceSource.NewArgumentNullException(nameof(memberList)); } if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (nameMatch == null) @@ -3884,7 +3884,7 @@ internal ReadOnlyPSMemberInfoCollection(PSMemberInfoInternalCollection member { if (members == null) { - throw PSTraceSource.NewArgumentNullException("members"); + throw PSTraceSource.NewArgumentNullException(nameof(members)); } _members = members; @@ -3902,7 +3902,7 @@ public T this[string name] { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } return _members[name]; @@ -3919,7 +3919,7 @@ public ReadOnlyPSMemberInfoCollection Match(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } return _members.Match(name); @@ -3936,7 +3936,7 @@ public ReadOnlyPSMemberInfoCollection Match(string name, PSMemberTypes member { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } return _members.Match(name, memberTypes); @@ -4069,7 +4069,7 @@ public override void Add(T member, bool preValidated) { if (member == null) { - throw PSTraceSource.NewArgumentNullException("member"); + throw PSTraceSource.NewArgumentNullException(nameof(member)); } // Save to a local variable to reduce property access. @@ -4101,7 +4101,7 @@ public override void Remove(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (IsReservedName(name)) @@ -4143,7 +4143,7 @@ public override T this[string name] { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (_members == null) @@ -4168,7 +4168,7 @@ public override ReadOnlyPSMemberInfoCollection Match(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } return Match(name, PSMemberTypes.All, MshMemberMatchOptions.None); @@ -4185,7 +4185,7 @@ public override ReadOnlyPSMemberInfoCollection Match(string name, PSMemberTyp { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } return Match(name, memberTypes, MshMemberMatchOptions.None); @@ -4203,7 +4203,7 @@ internal override ReadOnlyPSMemberInfoCollection Match(string name, PSMemberT { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } PSMemberInfoInternalCollection internalMembers = GetInternalMembers(matchOptions); @@ -4500,19 +4500,19 @@ internal PSMemberInfoIntegratingCollection(object owner, Collection Match(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } return Match(name, PSMemberTypes.All, MshMemberMatchOptions.None); @@ -4925,7 +4925,7 @@ public override ReadOnlyPSMemberInfoCollection Match(string name, PSMemberTyp { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } return Match(name, memberTypes, MshMemberMatchOptions.None); @@ -4945,7 +4945,7 @@ internal override ReadOnlyPSMemberInfoCollection Match(string name, PSMemberT { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (_mshOwner != null) diff --git a/src/System.Management.Automation/engine/MshObject.cs b/src/System.Management.Automation/engine/MshObject.cs index 7697f2b413e..79824980475 100644 --- a/src/System.Management.Automation/engine/MshObject.cs +++ b/src/System.Management.Automation/engine/MshObject.cs @@ -569,7 +569,7 @@ public PSObject(object obj) { if (obj == null) { - throw PSTraceSource.NewArgumentNullException("obj"); + throw PSTraceSource.NewArgumentNullException(nameof(obj)); } CommonInitialization(obj); @@ -584,14 +584,14 @@ protected PSObject(SerializationInfo info, StreamingContext context) { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } string serializedData = info.GetValue("CliXml", typeof(string)) as string; if (serializedData == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } PSObject result = PSObject.AsPSObject(PSSerializer.Deserialize(serializedData)); @@ -1051,7 +1051,7 @@ internal static PSObject AsPSObject(object obj, bool storeTypeNameAndInstanceMem { if (obj == null) { - throw PSTraceSource.NewArgumentNullException("obj"); + throw PSTraceSource.NewArgumentNullException(nameof(obj)); } if (obj is PSObject so) @@ -1815,7 +1815,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } // We create a wrapper PSObject, so that we can successfully deserialize it diff --git a/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs b/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs index 0ee6945f3a8..3beae965b55 100644 --- a/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs +++ b/src/System.Management.Automation/engine/MshObjectTypeDescriptor.cs @@ -171,7 +171,7 @@ public override object GetValue(object component) { if (component == null) { - throw PSTraceSource.NewArgumentNullException("component"); + throw PSTraceSource.NewArgumentNullException(nameof(component)); } PSObject mshObj = GetComponentPSObject(component); @@ -221,7 +221,7 @@ private static PSObject GetComponentPSObject(object component) PSObjectTypeDescriptor descriptor = component as PSObjectTypeDescriptor; if (descriptor == null) { - throw PSTraceSource.NewArgumentException("component", ExtendedTypeSystem.InvalidComponent, + throw PSTraceSource.NewArgumentException(nameof(component), ExtendedTypeSystem.InvalidComponent, "component", typeof(PSObject).Name, typeof(PSObjectTypeDescriptor).Name); @@ -270,7 +270,7 @@ public override void SetValue(object component, object value) { if (component == null) { - throw PSTraceSource.NewArgumentNullException("component"); + throw PSTraceSource.NewArgumentNullException(nameof(component)); } PSObject mshObj = GetComponentPSObject(component); diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index 45fb9582599..ef9053faf8f 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -161,7 +161,7 @@ internal NativeCommandProcessor(ApplicationInfo applicationInfo, ExecutionContex { if (applicationInfo == null) { - throw PSTraceSource.NewArgumentNullException("applicationInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(applicationInfo)); } _applicationInfo = applicationInfo; diff --git a/src/System.Management.Automation/engine/PSClassInfo.cs b/src/System.Management.Automation/engine/PSClassInfo.cs index 2a22f27b189..199f7f1b2b7 100644 --- a/src/System.Management.Automation/engine/PSClassInfo.cs +++ b/src/System.Management.Automation/engine/PSClassInfo.cs @@ -62,7 +62,7 @@ public sealed class PSClassMemberInfo internal PSClassMemberInfo(string name, string memberType, string defaultValue) { if (string.IsNullOrEmpty(name)) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); this.Name = name; this.TypeName = memberType; diff --git a/src/System.Management.Automation/engine/ParameterBinderBase.cs b/src/System.Management.Automation/engine/ParameterBinderBase.cs index e50395003fe..d6ecd705a30 100644 --- a/src/System.Management.Automation/engine/ParameterBinderBase.cs +++ b/src/System.Management.Automation/engine/ParameterBinderBase.cs @@ -243,7 +243,7 @@ private void ValidatePSTypeName( if (!psTypeNamesOfArgumentValue.Contains(psTypeNameRequestedByParameter, StringComparer.OrdinalIgnoreCase)) { // win8: 228176..The callers know when to ignore and when not to ignore invalid cast exceptions. - PSInvalidCastException e = new PSInvalidCastException(ErrorCategory.InvalidArgument.ToString(), + PSInvalidCastException e = new PSInvalidCastException(nameof(ErrorCategory.InvalidArgument), null, ParameterBinderStrings.MismatchedPSTypeName, (_invocationInfo != null) && (_invocationInfo.MyCommand != null) ? _invocationInfo.MyCommand.Name : string.Empty, @@ -337,12 +337,12 @@ internal virtual bool BindParameter( if (parameter == null) { - throw PSTraceSource.NewArgumentNullException("parameter"); + throw PSTraceSource.NewArgumentNullException(nameof(parameter)); } if (parameterMetadata == null) { - throw PSTraceSource.NewArgumentNullException("parameterMetadata"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterMetadata)); } using (bindingTracer.TraceScope( @@ -986,12 +986,12 @@ private object CoerceTypeAsNeeded( { if (argument == null) { - throw PSTraceSource.NewArgumentNullException("argument"); + throw PSTraceSource.NewArgumentNullException(nameof(argument)); } if (toType == null) { - throw PSTraceSource.NewArgumentNullException("toType"); + throw PSTraceSource.NewArgumentNullException(nameof(toType)); } // Construct the collection type information if it wasn't passed in. diff --git a/src/System.Management.Automation/engine/ParameterBinderController.cs b/src/System.Management.Automation/engine/ParameterBinderController.cs index 5105abbc298..a68192c7a90 100644 --- a/src/System.Management.Automation/engine/ParameterBinderController.cs +++ b/src/System.Management.Automation/engine/ParameterBinderController.cs @@ -872,7 +872,7 @@ protected void ThrowElaboratedBindingException(ParameterBindingException pbex) { if (pbex == null) { - throw PSTraceSource.NewArgumentNullException("pbex"); + throw PSTraceSource.NewArgumentNullException(nameof(pbex)); } Diagnostics.Assert(pbex.ErrorRecord != null, "ErrorRecord should not be null in a ParameterBindingException"); diff --git a/src/System.Management.Automation/engine/ParameterInfo.cs b/src/System.Management.Automation/engine/ParameterInfo.cs index 5878fdc400a..cf1784a7b62 100644 --- a/src/System.Management.Automation/engine/ParameterInfo.cs +++ b/src/System.Management.Automation/engine/ParameterInfo.cs @@ -32,7 +32,7 @@ internal CommandParameterInfo( { if (parameter == null) { - throw PSTraceSource.NewArgumentNullException("parameter"); + throw PSTraceSource.NewArgumentNullException(nameof(parameter)); } Name = parameter.Name; diff --git a/src/System.Management.Automation/engine/ParameterSetInfo.cs b/src/System.Management.Automation/engine/ParameterSetInfo.cs index 85a3cf042a6..c166f749b1c 100644 --- a/src/System.Management.Automation/engine/ParameterSetInfo.cs +++ b/src/System.Management.Automation/engine/ParameterSetInfo.cs @@ -52,12 +52,12 @@ internal CommandParameterSetInfo( Name = string.Empty; if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (parameterMetadata == null) { - throw PSTraceSource.NewArgumentNullException("parameterMetadata"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterMetadata)); } this.Name = name; diff --git a/src/System.Management.Automation/engine/ParameterSetSpecificMetadata.cs b/src/System.Management.Automation/engine/ParameterSetSpecificMetadata.cs index 7ffba7fd0dd..4cc4ca7540e 100644 --- a/src/System.Management.Automation/engine/ParameterSetSpecificMetadata.cs +++ b/src/System.Management.Automation/engine/ParameterSetSpecificMetadata.cs @@ -21,7 +21,7 @@ internal ParameterSetSpecificMetadata(ParameterAttribute attribute) { if (attribute == null) { - throw PSTraceSource.NewArgumentNullException("attribute"); + throw PSTraceSource.NewArgumentNullException(nameof(attribute)); } _attribute = attribute; diff --git a/src/System.Management.Automation/engine/PathInterfaces.cs b/src/System.Management.Automation/engine/PathInterfaces.cs index 342aec3cba0..d11a225797e 100644 --- a/src/System.Management.Automation/engine/PathInterfaces.cs +++ b/src/System.Management.Automation/engine/PathInterfaces.cs @@ -40,7 +40,7 @@ internal PathIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/ProgressRecord.cs b/src/System.Management.Automation/engine/ProgressRecord.cs index 086815105ef..f040e24e416 100644 --- a/src/System.Management.Automation/engine/ProgressRecord.cs +++ b/src/System.Management.Automation/engine/ProgressRecord.cs @@ -43,17 +43,17 @@ class ProgressRecord { // negative Ids are reserved to indicate "no id" for parent Ids. - throw PSTraceSource.NewArgumentOutOfRangeException("activityId", activityId, ProgressRecordStrings.ArgMayNotBeNegative, "activityId"); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(activityId), activityId, ProgressRecordStrings.ArgMayNotBeNegative, "activityId"); } if (string.IsNullOrEmpty(activity)) { - throw PSTraceSource.NewArgumentException("activity", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "activity"); + throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "activity"); } if (string.IsNullOrEmpty(statusDescription)) { - throw PSTraceSource.NewArgumentException("activity", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "statusDescription"); + throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "statusDescription"); } this.id = activityId; @@ -373,12 +373,12 @@ internal static int GetPercentageComplete(DateTime startTime, TimeSpan expectedD if (startTime > now) { - throw new ArgumentOutOfRangeException("startTime"); + throw new ArgumentOutOfRangeException(nameof(startTime)); } if (expectedDuration <= TimeSpan.Zero) { - throw new ArgumentOutOfRangeException("expectedDuration"); + throw new ArgumentOutOfRangeException(nameof(expectedDuration)); } /* @@ -474,7 +474,7 @@ internal static ProgressRecord FromPSObjectForRemoting(PSObject progressAsPSObje { if (progressAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("progressAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(progressAsPSObject)); } string activity = RemotingDecoder.GetPropertyValue(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_Activity); diff --git a/src/System.Management.Automation/engine/PropertyCmdletProviderInterfaces.cs b/src/System.Management.Automation/engine/PropertyCmdletProviderInterfaces.cs index e249a2b7d0c..9c1f9379190 100644 --- a/src/System.Management.Automation/engine/PropertyCmdletProviderInterfaces.cs +++ b/src/System.Management.Automation/engine/PropertyCmdletProviderInterfaces.cs @@ -38,7 +38,7 @@ internal PropertyCmdletProviderIntrinsics(Cmdlet cmdlet) { if (cmdlet == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdlet)); } _cmdlet = cmdlet; @@ -58,7 +58,7 @@ internal PropertyCmdletProviderIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/ProviderInterfaces.cs b/src/System.Management.Automation/engine/ProviderInterfaces.cs index c74b1336184..27e2680af5c 100644 --- a/src/System.Management.Automation/engine/ProviderInterfaces.cs +++ b/src/System.Management.Automation/engine/ProviderInterfaces.cs @@ -40,7 +40,7 @@ internal CmdletProviderManagementIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/ProxyCommand.cs b/src/System.Management.Automation/engine/ProxyCommand.cs index a3dca0da40a..54bce30c9d0 100644 --- a/src/System.Management.Automation/engine/ProxyCommand.cs +++ b/src/System.Management.Automation/engine/ProxyCommand.cs @@ -354,7 +354,7 @@ public static string GetHelpComments(PSObject help) { if (help == null) { - throw new ArgumentNullException("help"); + throw new ArgumentNullException(nameof(help)); } bool isHelpObject = false; diff --git a/src/System.Management.Automation/engine/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/PseudoParameterBinder.cs index 123c7291e10..bddbe643f59 100644 --- a/src/System.Management.Automation/engine/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/PseudoParameterBinder.cs @@ -124,7 +124,7 @@ internal override void BindParameter(string name, object value, CompiledCommandP { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } Target[name].Value = value; diff --git a/src/System.Management.Automation/engine/PseudoParameters.cs b/src/System.Management.Automation/engine/PseudoParameters.cs index 28be3daefc6..bccb2fb3f37 100644 --- a/src/System.Management.Automation/engine/PseudoParameters.cs +++ b/src/System.Management.Automation/engine/PseudoParameters.cs @@ -53,12 +53,12 @@ public RuntimeDefinedParameter(string name, Type parameterType, Collection GetChildItems(string[] paths, bool recurse, uint d { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -1251,7 +1251,7 @@ internal Collection GetChildItems(string[] paths, bool recurse, uint d { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } GetChildItems(path, recurse, depth, context); @@ -1307,12 +1307,12 @@ internal void GetChildItems( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } ProviderInfo provider = null; @@ -2229,7 +2229,7 @@ internal Collection GetChildNames( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -2240,7 +2240,7 @@ internal Collection GetChildNames( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } GetChildNames(path, returnContainers, recurse, depth, context); @@ -2320,7 +2320,7 @@ internal void GetChildNames( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } // Construct the include filter @@ -2979,7 +2979,7 @@ internal Collection RenameItem(string path, string newName, bool force { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -3037,7 +3037,7 @@ internal void RenameItem( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } ProviderInfo provider = null; @@ -3062,7 +3062,7 @@ internal void RenameItem( { ArgumentException argException = PSTraceSource.NewArgumentException( - "path", + nameof(path), SessionStateStrings.RenameMultipleItemError); context.WriteError( @@ -3345,7 +3345,7 @@ internal Collection NewItem(string[] paths, string name, string type, { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -3409,7 +3409,7 @@ internal void NewItem( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } foreach (string path in paths) @@ -3417,7 +3417,7 @@ internal void NewItem( string resolvePath = null; if (path == null) { - PSTraceSource.NewArgumentNullException("paths"); + PSTraceSource.NewArgumentNullException(nameof(paths)); } else if (path.EndsWith((":" + Path.DirectorySeparatorChar), StringComparison.Ordinal) || path.EndsWith((":" + Path.AltDirectorySeparatorChar), StringComparison.Ordinal)) @@ -3819,7 +3819,7 @@ internal bool HasChildItems(string path, bool force, bool literalPath) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -3871,7 +3871,7 @@ internal bool HasChildItems( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } ProviderInfo provider = null; @@ -3924,12 +3924,12 @@ internal bool HasChildItems( if (string.IsNullOrEmpty(providerId)) { - throw PSTraceSource.NewArgumentException("providerId"); + throw PSTraceSource.NewArgumentException(nameof(providerId)); } if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -4097,7 +4097,7 @@ internal Collection CopyItem(string[] paths, { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (copyPath == null) @@ -4163,7 +4163,7 @@ internal void CopyItem( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (copyPath == null) @@ -4260,7 +4260,7 @@ internal void CopyItem( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths; @@ -4839,7 +4839,7 @@ private string ValidateRemotePathAndGetRoot(string path, Runspaces.PSSession ses if (sourceIsRemote) { - ps.AddParameter("sourceIsRemote", true); + ps.AddParameter(nameof(sourceIsRemote), true); } op = Microsoft.PowerShell.Commands.SafeInvokeCommand.Invoke(ps, null, context); diff --git a/src/System.Management.Automation/engine/SessionStateContent.cs b/src/System.Management.Automation/engine/SessionStateContent.cs index 3ace73430c9..0f1cc74bc49 100644 --- a/src/System.Management.Automation/engine/SessionStateContent.cs +++ b/src/System.Management.Automation/engine/SessionStateContent.cs @@ -55,7 +55,7 @@ internal Collection GetContentReader(string[] paths, bool force, { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -107,7 +107,7 @@ internal Collection GetContentReader( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -119,7 +119,7 @@ internal Collection GetContentReader( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = @@ -396,7 +396,7 @@ internal Collection GetContentWriter(string[] paths, bool force, { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -448,7 +448,7 @@ internal Collection GetContentWriter( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -459,7 +459,7 @@ internal Collection GetContentWriter( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = @@ -738,7 +738,7 @@ internal void ClearContent(string[] paths, bool force, bool literalPath) { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -785,7 +785,7 @@ internal void ClearContent( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -795,7 +795,7 @@ internal void ClearContent( { if (path == null) { - PSTraceSource.NewArgumentNullException("paths"); + PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = diff --git a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs index abc6b867ae5..91228e4dd1b 100644 --- a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs @@ -65,7 +65,7 @@ internal PSDriveInfo NewDrive(PSDriveInfo drive, string scopeID) { if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } PSDriveInfo result = null; @@ -140,12 +140,12 @@ internal void NewDrive(PSDriveInfo drive, string scopeID, CmdletProviderContext { if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } if (!IsValidDriveName(drive.Name)) @@ -432,7 +432,7 @@ private PSDriveInfo GetDrive(string name, bool automount) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } PSDriveInfo result = null; @@ -528,7 +528,7 @@ internal PSDriveInfo GetDrive(string name, string scopeID) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } PSDriveInfo result = null; @@ -994,7 +994,7 @@ internal void RemoveDrive(string driveName, bool force, string scopeID) { if (driveName == null) { - throw PSTraceSource.NewArgumentNullException("driveName"); + throw PSTraceSource.NewArgumentNullException(nameof(driveName)); } PSDriveInfo drive = GetDrive(driveName, scopeID); @@ -1037,7 +1037,7 @@ internal void RemoveDrive( { if (driveName == null) { - throw PSTraceSource.NewArgumentNullException("driveName"); + throw PSTraceSource.NewArgumentNullException(nameof(driveName)); } Dbg.Diagnostics.Assert( @@ -1079,7 +1079,7 @@ internal void RemoveDrive(PSDriveInfo drive, bool force, string scopeID) { if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -1241,12 +1241,12 @@ private bool CanRemoveDrive(PSDriveInfo drive, CmdletProviderContext context) { if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } s_tracer.WriteLine("Drive name = {0}", drive.Name); diff --git a/src/System.Management.Automation/engine/SessionStateDynamicProperty.cs b/src/System.Management.Automation/engine/SessionStateDynamicProperty.cs index 4b6bfef05d7..575c3387d5e 100644 --- a/src/System.Management.Automation/engine/SessionStateDynamicProperty.cs +++ b/src/System.Management.Automation/engine/SessionStateDynamicProperty.cs @@ -70,12 +70,12 @@ internal Collection NewProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (property == null) { - throw PSTraceSource.NewArgumentNullException("property"); + throw PSTraceSource.NewArgumentNullException(nameof(property)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -141,12 +141,12 @@ internal void NewProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (property == null) { - throw PSTraceSource.NewArgumentNullException("property"); + throw PSTraceSource.NewArgumentNullException(nameof(property)); } ProviderInfo provider = null; @@ -156,7 +156,7 @@ internal void NewProperty( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = @@ -467,12 +467,12 @@ internal void RemoveProperty(string[] paths, string property, bool force, bool l { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (property == null) { - throw PSTraceSource.NewArgumentNullException("property"); + throw PSTraceSource.NewArgumentNullException(nameof(property)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -523,19 +523,19 @@ internal void RemoveProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (property == null) { - throw PSTraceSource.NewArgumentNullException("property"); + throw PSTraceSource.NewArgumentNullException(nameof(property)); } foreach (string path in paths) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -840,22 +840,22 @@ internal Collection CopyProperty( { if (sourcePaths == null) { - throw PSTraceSource.NewArgumentNullException("sourcePaths"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths)); } if (sourceProperty == null) { - throw PSTraceSource.NewArgumentNullException("sourceProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty)); } if (destinationPath == null) { - throw PSTraceSource.NewArgumentNullException("destinationPath"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationPath)); } if (destinationProperty == null) { - throw PSTraceSource.NewArgumentNullException("destinationProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -921,29 +921,29 @@ internal void CopyProperty( { if (sourcePaths == null) { - throw PSTraceSource.NewArgumentNullException("sourcePaths"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths)); } if (sourceProperty == null) { - throw PSTraceSource.NewArgumentNullException("sourceProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty)); } if (destinationPath == null) { - throw PSTraceSource.NewArgumentNullException("destinationPath"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationPath)); } if (destinationProperty == null) { - throw PSTraceSource.NewArgumentNullException("destinationProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty)); } foreach (string sourcePath in sourcePaths) { if (sourcePath == null) { - throw PSTraceSource.NewArgumentNullException("sourcePaths"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths)); } ProviderInfo provider = null; @@ -1327,22 +1327,22 @@ internal Collection MoveProperty( { if (sourcePaths == null) { - throw PSTraceSource.NewArgumentNullException("sourcePaths"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths)); } if (sourceProperty == null) { - throw PSTraceSource.NewArgumentNullException("sourceProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty)); } if (destinationPath == null) { - throw PSTraceSource.NewArgumentNullException("destinationPath"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationPath)); } if (destinationProperty == null) { - throw PSTraceSource.NewArgumentNullException("destinationProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -1411,22 +1411,22 @@ internal void MoveProperty( { if (sourcePaths == null) { - throw PSTraceSource.NewArgumentNullException("sourcePaths"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths)); } if (sourceProperty == null) { - throw PSTraceSource.NewArgumentNullException("sourceProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty)); } if (destinationPath == null) { - throw PSTraceSource.NewArgumentNullException("destinationPath"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationPath)); } if (destinationProperty == null) { - throw PSTraceSource.NewArgumentNullException("destinationProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty)); } ProviderInfo provider = null; @@ -1453,7 +1453,7 @@ internal void MoveProperty( { ArgumentException argException = PSTraceSource.NewArgumentException( - "destinationPath", + nameof(destinationPath), SessionStateStrings.MovePropertyDestinationResolveToSingle); context.WriteError(new ErrorRecord(argException, argException.GetType().FullName, ErrorCategory.InvalidArgument, destinationProviderPaths)); @@ -1464,7 +1464,7 @@ internal void MoveProperty( { if (sourcePath == null) { - throw PSTraceSource.NewArgumentNullException("sourcePaths"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths)); } Collection providerPaths = @@ -1805,17 +1805,17 @@ internal Collection RenameProperty( { if (sourcePaths == null) { - throw PSTraceSource.NewArgumentNullException("sourcePaths"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths)); } if (sourceProperty == null) { - throw PSTraceSource.NewArgumentNullException("sourceProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty)); } if (destinationProperty == null) { - throw PSTraceSource.NewArgumentNullException("destinationProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -1874,24 +1874,24 @@ internal void RenameProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (sourceProperty == null) { - throw PSTraceSource.NewArgumentNullException("sourceProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty)); } if (destinationProperty == null) { - throw PSTraceSource.NewArgumentNullException("destinationProperty"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty)); } foreach (string path in paths) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; diff --git a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs index b04e5e8d275..2e45499f485 100644 --- a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs @@ -154,7 +154,7 @@ internal FunctionInfo GetFunction(string name, CommandOrigin origin) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } FunctionInfo result = null; @@ -269,12 +269,12 @@ internal FunctionInfo SetFunctionRaw( { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (function == null) { - throw PSTraceSource.NewArgumentNullException("function"); + throw PSTraceSource.NewArgumentNullException(nameof(function)); } string originalName = name; @@ -504,12 +504,12 @@ internal FunctionInfo SetFunction( { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (function == null) { - throw PSTraceSource.NewArgumentNullException("function"); + throw PSTraceSource.NewArgumentNullException(nameof(function)); } string originalName = name; @@ -583,12 +583,12 @@ internal FunctionInfo SetFunction( { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } if (function == null) { - throw PSTraceSource.NewArgumentNullException("function"); + throw PSTraceSource.NewArgumentNullException(nameof(function)); } string originalName = name; @@ -711,7 +711,7 @@ internal void RemoveFunction(string name, bool force, CommandOrigin origin) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } // Use the scope enumerator to find an existing function diff --git a/src/System.Management.Automation/engine/SessionStateItem.cs b/src/System.Management.Automation/engine/SessionStateItem.cs index aa1d50aab27..3d5262bf6c0 100644 --- a/src/System.Management.Automation/engine/SessionStateItem.cs +++ b/src/System.Management.Automation/engine/SessionStateItem.cs @@ -56,7 +56,7 @@ internal Collection GetItem(string[] paths, bool force, bool literalPa { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -114,7 +114,7 @@ internal void GetItem( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -124,7 +124,7 @@ internal void GetItem( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = @@ -395,7 +395,7 @@ internal Collection SetItem(string[] paths, object value, bool force, { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -451,14 +451,14 @@ internal void SetItem( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } foreach (string path in paths) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -748,7 +748,7 @@ internal Collection ClearItem(string[] paths, bool force, bool literal { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -800,7 +800,7 @@ internal void ClearItem( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -810,7 +810,7 @@ internal void ClearItem( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = @@ -1079,7 +1079,7 @@ internal void InvokeDefaultAction(string[] paths, bool literalPath) { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -1127,7 +1127,7 @@ internal void InvokeDefaultAction( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -1137,7 +1137,7 @@ internal void InvokeDefaultAction( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = diff --git a/src/System.Management.Automation/engine/SessionStateLocationAPIs.cs b/src/System.Management.Automation/engine/SessionStateLocationAPIs.cs index 591c20f184a..ca048aa0931 100644 --- a/src/System.Management.Automation/engine/SessionStateLocationAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateLocationAPIs.cs @@ -75,7 +75,7 @@ internal PathInfo GetNamespaceCurrentLocation(string namespaceID) { if (namespaceID == null) { - throw PSTraceSource.NewArgumentNullException("namespaceID"); + throw PSTraceSource.NewArgumentNullException(nameof(namespaceID)); } // If namespace ID is empty, we will use the current working drive @@ -236,7 +236,7 @@ internal PathInfo SetLocation(string path, CmdletProviderContext context, bool l { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } PathInfo current = CurrentLocation; @@ -519,7 +519,7 @@ internal PathInfo SetLocation(string path, CmdletProviderContext context, bool l throw PSTraceSource.NewArgumentException( - "path", + nameof(path), SessionStateStrings.PathResolvedToMultiple, originalPath); } @@ -636,7 +636,7 @@ internal bool IsCurrentLocationOrAncestor(string path, CmdletProviderContext con if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } PSDriveInfo drive = null; @@ -913,7 +913,7 @@ internal PathInfo PopLocation(string stackName) { throw PSTraceSource.NewArgumentException( - "stackName", + nameof(stackName), SessionStateStrings.StackNameResolvedToMultiple, stackName); } @@ -935,7 +935,7 @@ internal PathInfo PopLocation(string stackName) { throw PSTraceSource.NewArgumentException( - "stackName", + nameof(stackName), SessionStateStrings.StackNotFound, stackName); } @@ -1012,7 +1012,7 @@ internal PathInfoStack LocationStack(string stackName) } else { - throw PSTraceSource.NewArgumentException("stackName"); + throw PSTraceSource.NewArgumentException(nameof(stackName)); } } diff --git a/src/System.Management.Automation/engine/SessionStateNavigation.cs b/src/System.Management.Automation/engine/SessionStateNavigation.cs index f42e79433ad..4afb9218dd7 100644 --- a/src/System.Management.Automation/engine/SessionStateNavigation.cs +++ b/src/System.Management.Automation/engine/SessionStateNavigation.cs @@ -48,7 +48,7 @@ internal string GetParentPath(string path, string root) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -125,7 +125,7 @@ internal string GetParentPath( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext getProviderPathContext = @@ -469,7 +469,7 @@ internal string NormalizeRelativePath(string path, string basePath) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -517,7 +517,7 @@ internal string NormalizeRelativePath( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext getProviderPathContext = @@ -546,7 +546,7 @@ internal string NormalizeRelativePath( // Since the provider didn't write an error, and we didn't get any // results ourselves, we need to write out our own error. - Exception e = PSTraceSource.NewArgumentException("path"); + Exception e = PSTraceSource.NewArgumentException(nameof(path)); context.WriteError(new ErrorRecord(e, "NormalizePathNullResult", ErrorCategory.InvalidArgument, path)); return null; } @@ -816,13 +816,13 @@ internal string MakePath( if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } if (parent == null && child == null) { - throw PSTraceSource.NewArgumentException("parent"); + throw PSTraceSource.NewArgumentException(nameof(parent)); } // Set the drive data for the context @@ -1046,7 +1046,7 @@ internal string GetChildName(string path) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -1117,7 +1117,7 @@ internal string GetChildName( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } PSDriveInfo drive = null; @@ -1340,7 +1340,7 @@ internal Collection MoveItem(string[] paths, string destination, bool { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -1398,12 +1398,12 @@ internal void MoveItem( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (destination == null) { - throw PSTraceSource.NewArgumentNullException("destination"); + throw PSTraceSource.NewArgumentNullException(nameof(destination)); } ProviderInfo provider = null; @@ -1420,7 +1420,7 @@ internal void MoveItem( { ArgumentException argException = PSTraceSource.NewArgumentException( - "destination", + nameof(destination), SessionStateStrings.MoveItemOneDestination); context.WriteError(new ErrorRecord(argException, argException.GetType().FullName, ErrorCategory.InvalidArgument, destination)); @@ -1431,7 +1431,7 @@ internal void MoveItem( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } Collection providerPaths = @@ -1496,7 +1496,7 @@ internal void MoveItem( { ArgumentException argException = PSTraceSource.NewArgumentException( - "destination", + nameof(destination), SessionStateStrings.MoveItemSourceAndDestinationNotSameProvider); context.WriteError(new ErrorRecord(argException, argException.GetType().FullName, ErrorCategory.InvalidArgument, providerPaths)); diff --git a/src/System.Management.Automation/engine/SessionStateProperty.cs b/src/System.Management.Automation/engine/SessionStateProperty.cs index 003da25d93f..d4568d2ebb3 100644 --- a/src/System.Management.Automation/engine/SessionStateProperty.cs +++ b/src/System.Management.Automation/engine/SessionStateProperty.cs @@ -116,14 +116,14 @@ internal void GetProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } foreach (string path in paths) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -416,7 +416,7 @@ internal Collection SetProperty(string[] paths, PSObject property, boo { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (property == null) @@ -480,19 +480,19 @@ internal void SetProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (property == null) { - throw PSTraceSource.NewArgumentNullException("property"); + throw PSTraceSource.NewArgumentNullException(nameof(property)); } foreach (string path in paths) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; @@ -789,12 +789,12 @@ internal void ClearProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (propertyToClear == null) { - throw PSTraceSource.NewArgumentNullException("propertyToClear"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyToClear)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -845,19 +845,19 @@ internal void ClearProperty( { if (paths == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } if (propertyToClear == null) { - throw PSTraceSource.NewArgumentNullException("propertyToClear"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyToClear)); } foreach (string path in paths) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("paths"); + throw PSTraceSource.NewArgumentNullException(nameof(paths)); } ProviderInfo provider = null; diff --git a/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs b/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs index 61d21413604..d6971865232 100644 --- a/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs @@ -254,7 +254,7 @@ internal Provider.CmdletProvider GetProviderInstance(string providerId) { if (providerId == null) { - throw PSTraceSource.NewArgumentNullException("providerId"); + throw PSTraceSource.NewArgumentNullException(nameof(providerId)); } ProviderInfo provider = GetSingleProvider(providerId); @@ -278,7 +278,7 @@ internal Provider.CmdletProvider GetProviderInstance(ProviderInfo provider) { if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } return provider.CreateInstance(); @@ -347,7 +347,7 @@ internal DriveCmdletProvider GetDriveProviderInstance(string providerId) { if (providerId == null) { - throw PSTraceSource.NewArgumentNullException("providerId"); + throw PSTraceSource.NewArgumentNullException(nameof(providerId)); } DriveCmdletProvider driveCmdletProvider = @@ -382,7 +382,7 @@ internal DriveCmdletProvider GetDriveProviderInstance(ProviderInfo provider) { if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } DriveCmdletProvider driveCmdletProvider = @@ -417,7 +417,7 @@ private static DriveCmdletProvider GetDriveProviderInstance(CmdletProvider provi { if (providerInstance == null) { - throw PSTraceSource.NewArgumentNullException("providerInstance"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInstance)); } DriveCmdletProvider driveCmdletProvider = @@ -455,7 +455,7 @@ internal ItemCmdletProvider GetItemProviderInstance(string providerId) { if (providerId == null) { - throw PSTraceSource.NewArgumentNullException("providerId"); + throw PSTraceSource.NewArgumentNullException(nameof(providerId)); } ItemCmdletProvider itemCmdletProvider = @@ -490,7 +490,7 @@ internal ItemCmdletProvider GetItemProviderInstance(ProviderInfo provider) { if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } ItemCmdletProvider itemCmdletProvider = @@ -525,7 +525,7 @@ private static ItemCmdletProvider GetItemProviderInstance(CmdletProvider provide { if (providerInstance == null) { - throw PSTraceSource.NewArgumentNullException("providerInstance"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInstance)); } ItemCmdletProvider itemCmdletProvider = @@ -563,7 +563,7 @@ internal ContainerCmdletProvider GetContainerProviderInstance(string providerId) { if (providerId == null) { - throw PSTraceSource.NewArgumentNullException("providerId"); + throw PSTraceSource.NewArgumentNullException(nameof(providerId)); } ContainerCmdletProvider containerCmdletProvider = @@ -598,7 +598,7 @@ internal ContainerCmdletProvider GetContainerProviderInstance(ProviderInfo provi { if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } ContainerCmdletProvider containerCmdletProvider = @@ -633,7 +633,7 @@ private static ContainerCmdletProvider GetContainerProviderInstance(CmdletProvid { if (providerInstance == null) { - throw PSTraceSource.NewArgumentNullException("providerInstance"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInstance)); } ContainerCmdletProvider containerCmdletProvider = @@ -668,7 +668,7 @@ internal NavigationCmdletProvider GetNavigationProviderInstance(ProviderInfo pro { if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } NavigationCmdletProvider navigationCmdletProvider = @@ -707,7 +707,7 @@ private static NavigationCmdletProvider GetNavigationProviderInstance(CmdletProv { if (providerInstance == null) { - throw PSTraceSource.NewArgumentNullException("providerInstance"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInstance)); } NavigationCmdletProvider navigationCmdletProvider = @@ -742,7 +742,7 @@ internal bool IsProviderLoaded(string name) if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } // Get the provider from the providers container @@ -780,7 +780,7 @@ internal Collection GetProvider(string name) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } PSSnapinQualifiedName providerName = PSSnapinQualifiedName.GetInstance(name); @@ -987,7 +987,7 @@ internal void InitializeProvider( { if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } if (context == null) @@ -1105,7 +1105,7 @@ internal ProviderInfo NewProvider(ProviderInfo provider) { if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } // Check to see if the provider already exists. @@ -1394,12 +1394,12 @@ internal void RemoveProvider( { if (context == null) { - throw PSTraceSource.NewArgumentNullException("context"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } if (string.IsNullOrEmpty(providerName)) { - throw PSTraceSource.NewArgumentException("providerName"); + throw PSTraceSource.NewArgumentException(nameof(providerName)); } bool errors = false; diff --git a/src/System.Management.Automation/engine/SessionStatePublic.cs b/src/System.Management.Automation/engine/SessionStatePublic.cs index de23eff9479..0dca57054db 100644 --- a/src/System.Management.Automation/engine/SessionStatePublic.cs +++ b/src/System.Management.Automation/engine/SessionStatePublic.cs @@ -28,7 +28,7 @@ internal SessionState(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentNullException("sessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(sessionState)); } _sessionState = sessionState; @@ -273,7 +273,7 @@ public static bool IsVisible(CommandOrigin origin, PSVariable variable) return true; if (variable == null) { - throw PSTraceSource.NewArgumentNullException("variable"); + throw PSTraceSource.NewArgumentNullException(nameof(variable)); } return (variable.Visibility == SessionStateEntryVisibility.Public); @@ -290,7 +290,7 @@ public static bool IsVisible(CommandOrigin origin, CommandInfo commandInfo) return true; if (commandInfo == null) { - throw PSTraceSource.NewArgumentNullException("commandInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(commandInfo)); } return (commandInfo.Visibility == SessionStateEntryVisibility.Public); diff --git a/src/System.Management.Automation/engine/SessionStateScope.cs b/src/System.Management.Automation/engine/SessionStateScope.cs index aac49ab5a4c..382df13dd1d 100644 --- a/src/System.Management.Automation/engine/SessionStateScope.cs +++ b/src/System.Management.Automation/engine/SessionStateScope.cs @@ -120,7 +120,7 @@ internal void NewDrive(PSDriveInfo newDrive) { if (newDrive == null) { - throw PSTraceSource.NewArgumentNullException("newDrive"); + throw PSTraceSource.NewArgumentNullException(nameof(newDrive)); } // Ensure that multiple threads do not try to modify the @@ -171,7 +171,7 @@ internal void RemoveDrive(PSDriveInfo drive) { if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } if (_drives == null) @@ -222,7 +222,7 @@ internal PSDriveInfo GetDrive(string name) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } PSDriveInfo result = null; diff --git a/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs b/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs index 574e2266638..73cf89cebdf 100644 --- a/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs +++ b/src/System.Management.Automation/engine/SessionStateSecurityDescriptorInterface.cs @@ -32,7 +32,7 @@ internal static ISecurityDescriptorCmdletProvider GetPermissionProviderInstance( { if (providerInstance == null) { - throw PSTraceSource.NewArgumentNullException("providerInstance"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInstance)); } ISecurityDescriptorCmdletProvider permissionCmdletProvider = @@ -69,7 +69,7 @@ internal Collection GetSecurityDescriptor(string path, { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -110,7 +110,7 @@ internal void GetSecurityDescriptor( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } ProviderInfo provider = null; @@ -200,12 +200,12 @@ internal Collection SetSecurityDescriptor(string path, ObjectSecurity { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (securityDescriptor == null) { - throw PSTraceSource.NewArgumentNullException("securityDescriptor"); + throw PSTraceSource.NewArgumentNullException(nameof(securityDescriptor)); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); @@ -247,12 +247,12 @@ internal void SetSecurityDescriptor( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (securityDescriptor == null) { - throw PSTraceSource.NewArgumentNullException("securityDescriptor"); + throw PSTraceSource.NewArgumentNullException(nameof(securityDescriptor)); } ProviderInfo provider = null; @@ -394,7 +394,7 @@ internal ObjectSecurity NewSecurityDescriptorFromPath( if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } ProviderInfo provider = null; @@ -419,7 +419,7 @@ internal ObjectSecurity NewSecurityDescriptorFromPath( } else { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } return sd; @@ -533,12 +533,12 @@ internal ObjectSecurity NewSecurityDescriptorOfType( if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } if (providerInstance == null) { - throw PSTraceSource.NewArgumentNullException("providerInstance"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInstance)); } // This just verifies that the provider supports the interface. diff --git a/src/System.Management.Automation/engine/SessionStateUtils.cs b/src/System.Management.Automation/engine/SessionStateUtils.cs index 4eaf5b23312..7c684abd1c3 100644 --- a/src/System.Management.Automation/engine/SessionStateUtils.cs +++ b/src/System.Management.Automation/engine/SessionStateUtils.cs @@ -153,7 +153,7 @@ internal static bool CollectionContainsValue(IEnumerable collection, object valu { if (collection == null) { - throw new ArgumentNullException("collection"); + throw new ArgumentNullException(nameof(collection)); } bool result = false; diff --git a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs index 9ad3b6eddcd..9b4028314b8 100644 --- a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs @@ -54,7 +54,7 @@ internal PSVariable GetVariable(string name, CommandOrigin origin) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } VariablePath variablePath = new VariablePath(name, VariablePathFlags.Variable | VariablePathFlags.Unqualified); @@ -114,7 +114,7 @@ internal object GetVariableValue(string name) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } VariablePath variablePath = new VariablePath(name); @@ -287,7 +287,7 @@ internal object GetVariableValueFromProvider( if (variablePath == null) { - throw PSTraceSource.NewArgumentNullException("variablePath"); + throw PSTraceSource.NewArgumentNullException(nameof(variablePath)); } Dbg.Diagnostics.Assert( @@ -542,7 +542,7 @@ internal PSVariable GetVariableItem( if (variablePath == null) { - throw PSTraceSource.NewArgumentNullException("variablePath"); + throw PSTraceSource.NewArgumentNullException(nameof(variablePath)); } Dbg.Diagnostics.Assert(variablePath.IsVariable, "Can't get variable w/ non-variable path"); @@ -621,7 +621,7 @@ internal PSVariable GetVariableAtScope(string name, string scopeID) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } VariablePath variablePath = new VariablePath(name); @@ -685,7 +685,7 @@ internal object GetVariableValueAtScope(string name, string scopeID) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } VariablePath variablePath = new VariablePath(name); @@ -956,7 +956,7 @@ internal void SetVariableValue(string name, object newValue, CommandOrigin origi { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } VariablePath variablePath = new VariablePath(name); @@ -1030,7 +1030,7 @@ internal object SetVariable(PSVariable variable, bool force, CommandOrigin origi { if (variable == null || string.IsNullOrEmpty(variable.Name)) { - throw PSTraceSource.NewArgumentException("variable"); + throw PSTraceSource.NewArgumentException(nameof(variable)); } VariablePath variablePath = new VariablePath(variable.Name, VariablePathFlags.Variable | VariablePathFlags.Unqualified); @@ -1138,7 +1138,7 @@ internal object SetVariable( object result = null; if (variablePath == null) { - throw PSTraceSource.NewArgumentNullException("variablePath"); + throw PSTraceSource.NewArgumentNullException(nameof(variablePath)); } CmdletProviderContext context = null; @@ -1405,7 +1405,7 @@ internal object SetVariableAtScope(PSVariable variable, string scopeID, bool for { if (variable == null || string.IsNullOrEmpty(variable.Name)) { - throw PSTraceSource.NewArgumentException("variable"); + throw PSTraceSource.NewArgumentException(nameof(variable)); } SessionStateScope lookupScope = GetScopeByID(scopeID); @@ -1441,7 +1441,7 @@ internal object NewVariable(PSVariable variable, bool force) { if (variable == null || string.IsNullOrEmpty(variable.Name)) { - throw PSTraceSource.NewArgumentException("variable"); + throw PSTraceSource.NewArgumentException(nameof(variable)); } return @@ -1485,7 +1485,7 @@ internal object NewVariableAtScope(PSVariable variable, string scopeID, bool for { if (variable == null || string.IsNullOrEmpty(variable.Name)) { - throw PSTraceSource.NewArgumentException("variable"); + throw PSTraceSource.NewArgumentException(nameof(variable)); } // The lookup scope from above is ignored and the scope is retrieved by @@ -1564,7 +1564,7 @@ internal void RemoveVariable(string name, bool force) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } VariablePath variablePath = new VariablePath(name); @@ -1623,7 +1623,7 @@ internal void RemoveVariable(PSVariable variable, bool force) { if (variable == null) { - throw PSTraceSource.NewArgumentNullException("variable"); + throw PSTraceSource.NewArgumentNullException(nameof(variable)); } VariablePath variablePath = new VariablePath(variable.Name); @@ -1698,7 +1698,7 @@ internal void RemoveVariableAtScope(string name, string scopeID, bool force) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } VariablePath variablePath = new VariablePath(name); @@ -1780,7 +1780,7 @@ internal void RemoveVariableAtScope(PSVariable variable, string scopeID, bool fo { if (variable == null) { - throw PSTraceSource.NewArgumentNullException("variable"); + throw PSTraceSource.NewArgumentNullException(nameof(variable)); } VariablePath variablePath = new VariablePath(variable.Name); diff --git a/src/System.Management.Automation/engine/ShellVariable.cs b/src/System.Management.Automation/engine/ShellVariable.cs index 42cc174083b..fd2b8b34a6d 100644 --- a/src/System.Management.Automation/engine/ShellVariable.cs +++ b/src/System.Management.Automation/engine/ShellVariable.cs @@ -159,7 +159,7 @@ public PSVariable( { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } Name = name; diff --git a/src/System.Management.Automation/engine/ThirdPartyAdapter.cs b/src/System.Management.Automation/engine/ThirdPartyAdapter.cs index 75e958693d9..9840aaa0555 100644 --- a/src/System.Management.Automation/engine/ThirdPartyAdapter.cs +++ b/src/System.Management.Automation/engine/ThirdPartyAdapter.cs @@ -298,7 +298,7 @@ public virtual Collection GetTypeNameHierarchy(object baseObject) { if (baseObject == null) { - throw new ArgumentNullException("baseObject"); + throw new ArgumentNullException(nameof(baseObject)); } Collection types = new Collection(); diff --git a/src/System.Management.Automation/engine/TypeMetadata.cs b/src/System.Management.Automation/engine/TypeMetadata.cs index 76f22734f8a..192042a3def 100644 --- a/src/System.Management.Automation/engine/TypeMetadata.cs +++ b/src/System.Management.Automation/engine/TypeMetadata.cs @@ -51,7 +51,7 @@ internal ParameterSetMetadata(ParameterSetMetadata other) { if (other == null) { - throw PSTraceSource.NewArgumentNullException("other"); + throw PSTraceSource.NewArgumentNullException(nameof(other)); } _helpMessage = other._helpMessage; @@ -411,7 +411,7 @@ public ParameterMetadata(string name, Type parameterType) { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } _name = name; @@ -431,7 +431,7 @@ public ParameterMetadata(ParameterMetadata other) { if (other == null) { - throw PSTraceSource.NewArgumentNullException("other"); + throw PSTraceSource.NewArgumentNullException(nameof(other)); } _isDynamic = other._isDynamic; @@ -625,7 +625,7 @@ public static Dictionary GetParameterMetadata(Type ty { if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } CommandMetadata cmdMetaData = new CommandMetadata(type); @@ -1165,7 +1165,7 @@ internal static InternalParameterMetadata Get(Type type, ExecutionContext contex { if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } InternalParameterMetadata result; @@ -1208,7 +1208,7 @@ internal InternalParameterMetadata(RuntimeDefinedParameterDictionary runtimeDefi { if (runtimeDefinedParameters == null) { - throw PSTraceSource.NewArgumentNullException("runtimeDefinedParameters"); + throw PSTraceSource.NewArgumentNullException(nameof(runtimeDefinedParameters)); } ConstructCompiledParametersUsingRuntimeDefinedParameters(runtimeDefinedParameters, processingDynamicParameters, checkNames); @@ -1236,7 +1236,7 @@ internal InternalParameterMetadata(Type type, bool processingDynamicParameters) { if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } _type = type; diff --git a/src/System.Management.Automation/engine/TypeTable.cs b/src/System.Management.Automation/engine/TypeTable.cs index c6d52a7ff1b..0f2fab28cc0 100644 --- a/src/System.Management.Automation/engine/TypeTable.cs +++ b/src/System.Management.Automation/engine/TypeTable.cs @@ -1606,7 +1606,7 @@ protected override void SetItem(int index, string item) { if (string.IsNullOrEmpty(item)) { - throw PSTraceSource.NewArgumentException("item"); + throw PSTraceSource.NewArgumentException(nameof(item)); } base.SetItem(index, item); @@ -1623,7 +1623,7 @@ protected override void InsertItem(int index, string item) { if (string.IsNullOrEmpty(item)) { - throw PSTraceSource.NewArgumentException("item"); + throw PSTraceSource.NewArgumentException(nameof(item)); } base.InsertItem(index, item); @@ -1672,7 +1672,7 @@ public ConsolidatedString(IEnumerable strings) string str = this[i]; if (string.IsNullOrEmpty(str)) { - throw PSTraceSource.NewArgumentException("strings"); + throw PSTraceSource.NewArgumentException(nameof(strings)); } } @@ -1816,7 +1816,7 @@ protected TypeTableLoadException(SerializationInfo info, StreamingContext contex { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } int errorCount = info.GetInt32("ErrorCount"); @@ -1843,7 +1843,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -1912,7 +1912,7 @@ private TypeData() public TypeData(string typeName) : this() { if (string.IsNullOrWhiteSpace(typeName)) - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); this.TypeName = typeName; } @@ -1930,7 +1930,7 @@ public TypeData(Type type) : this() { if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } this.TypeName = type.FullName; @@ -2367,7 +2367,7 @@ internal TypeMemberData(string name) { if (string.IsNullOrWhiteSpace(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } Name = name; @@ -2716,7 +2716,7 @@ public PropertySetData(IEnumerable referencedProperties) { if (referencedProperties == null) { - throw PSTraceSource.NewArgumentNullException("referencedProperties"); + throw PSTraceSource.NewArgumentNullException(nameof(referencedProperties)); } ReferencedProperties = new Collection(new List(referencedProperties)); @@ -3147,7 +3147,7 @@ private static bool CheckStandardMembers(ConcurrentBag errors, string ty TypesXmlStrings.MemberMustBePresent, PropertySerializationSet, SerializationMethodNode, - SerializationMethod.SpecificProperties.ToString(), + nameof(SerializationMethod.SpecificProperties), InheritPropertySerializationSet, "false"); serializationSettingsOk = false; @@ -3922,7 +3922,7 @@ internal TypeTable(IEnumerable typeFiles, AuthorizationManager authoriza { if (typeFiles == null) { - throw PSTraceSource.NewArgumentNullException("typeFiles"); + throw PSTraceSource.NewArgumentNullException(nameof(typeFiles)); } ConcurrentBag errors = new ConcurrentBag(); @@ -4668,7 +4668,7 @@ private void UpdateWithModuleContents( public void AddType(TypeData typeData) { if (typeData == null) - throw PSTraceSource.NewArgumentNullException("typeData"); + throw PSTraceSource.NewArgumentNullException(nameof(typeData)); Dbg.Assert(isShared, "This method should only be called by the developer user. It should not be used internally."); @@ -4695,7 +4695,7 @@ public void RemoveType(string typeName) { if (string.IsNullOrEmpty(typeName)) { - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); } Dbg.Assert(isShared, "This method should only be called by the developer user. It should not be used internally."); @@ -4741,12 +4741,12 @@ internal void Update( { if (filePath == null) { - throw new ArgumentNullException("filePath"); + throw new ArgumentNullException(nameof(filePath)); } if (errors == null) { - throw new ArgumentNullException("errors"); + throw new ArgumentNullException(nameof(errors)); } if (isShared) @@ -4818,9 +4818,9 @@ internal void Update( bool isRemove) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (errors == null) - throw new ArgumentNullException("errors"); + throw new ArgumentNullException(nameof(errors)); if (isShared) { diff --git a/src/System.Management.Automation/engine/UserFeedbackParameters.cs b/src/System.Management.Automation/engine/UserFeedbackParameters.cs index e74e309b3b1..feb1464d922 100644 --- a/src/System.Management.Automation/engine/UserFeedbackParameters.cs +++ b/src/System.Management.Automation/engine/UserFeedbackParameters.cs @@ -18,7 +18,7 @@ internal PagingParameters(MshCommandRuntime commandRuntime) { if (commandRuntime == null) { - throw PSTraceSource.NewArgumentNullException("commandRuntime"); + throw PSTraceSource.NewArgumentNullException(nameof(commandRuntime)); } commandRuntime.PagingParameters = this; @@ -116,7 +116,7 @@ internal ShouldProcessParameters(MshCommandRuntime commandRuntime) { if (commandRuntime == null) { - throw PSTraceSource.NewArgumentNullException("commandRuntime"); + throw PSTraceSource.NewArgumentNullException(nameof(commandRuntime)); } _commandRuntime = commandRuntime; diff --git a/src/System.Management.Automation/engine/VariableAttributeCollection.cs b/src/System.Management.Automation/engine/VariableAttributeCollection.cs index 918b040a0f6..f41bb3380ba 100644 --- a/src/System.Management.Automation/engine/VariableAttributeCollection.cs +++ b/src/System.Management.Automation/engine/VariableAttributeCollection.cs @@ -30,7 +30,7 @@ internal PSVariableAttributeCollection(PSVariable variable) { if (variable == null) { - throw PSTraceSource.NewArgumentNullException("variable"); + throw PSTraceSource.NewArgumentNullException(nameof(variable)); } _variable = variable; diff --git a/src/System.Management.Automation/engine/VariableInterfaces.cs b/src/System.Management.Automation/engine/VariableInterfaces.cs index 60d23f9e12a..90411860b6d 100644 --- a/src/System.Management.Automation/engine/VariableInterfaces.cs +++ b/src/System.Management.Automation/engine/VariableInterfaces.cs @@ -35,7 +35,7 @@ internal PSVariableIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { - throw PSTraceSource.NewArgumentException("sessionState"); + throw PSTraceSource.NewArgumentException(nameof(sessionState)); } _sessionState = sessionState; diff --git a/src/System.Management.Automation/engine/VariablePath.cs b/src/System.Management.Automation/engine/VariablePath.cs index 17cf9b95fac..0e33ae620c5 100644 --- a/src/System.Management.Automation/engine/VariablePath.cs +++ b/src/System.Management.Automation/engine/VariablePath.cs @@ -83,7 +83,7 @@ internal VariablePath(string path, VariablePathFlags knownFlags) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } _userPath = path; diff --git a/src/System.Management.Automation/engine/cmdlet.cs b/src/System.Management.Automation/engine/cmdlet.cs index 4a330b34ed0..00890bb31a4 100644 --- a/src/System.Management.Automation/engine/cmdlet.cs +++ b/src/System.Management.Automation/engine/cmdlet.cs @@ -252,10 +252,10 @@ public virtual string GetResourceString(string baseName, string resourceId) using (PSTransactionManager.GetEngineProtectionScope()) { if (string.IsNullOrEmpty(baseName)) - throw PSTraceSource.NewArgumentNullException("baseName"); + throw PSTraceSource.NewArgumentNullException(nameof(baseName)); if (string.IsNullOrEmpty(resourceId)) - throw PSTraceSource.NewArgumentNullException("resourceId"); + throw PSTraceSource.NewArgumentNullException(nameof(resourceId)); ResourceManager manager = ResourceManagerCache.GetResourceManager(this.GetType().Assembly, baseName); string retValue = null; @@ -266,12 +266,12 @@ public virtual string GetResourceString(string baseName, string resourceId) } catch (MissingManifestResourceException) { - throw PSTraceSource.NewArgumentException("baseName", GetErrorText.ResourceBaseNameFailure, baseName); + throw PSTraceSource.NewArgumentException(nameof(baseName), GetErrorText.ResourceBaseNameFailure, baseName); } if (retValue == null) { - throw PSTraceSource.NewArgumentException("resourceId", GetErrorText.ResourceIdFailure, resourceId); + throw PSTraceSource.NewArgumentException(nameof(resourceId), GetErrorText.ResourceIdFailure, resourceId); } return retValue; @@ -1719,7 +1719,7 @@ public void ThrowTerminatingError(ErrorRecord errorRecord) using (PSTransactionManager.GetEngineProtectionScope()) { if (errorRecord == null) - throw new ArgumentNullException("errorRecord"); + throw new ArgumentNullException(nameof(errorRecord)); if (commandRuntime != null) { diff --git a/src/System.Management.Automation/engine/debugger/debugger.cs b/src/System.Management.Automation/engine/debugger/debugger.cs index ab715b053ff..0bc4595c390 100644 --- a/src/System.Management.Automation/engine/debugger/debugger.cs +++ b/src/System.Management.Automation/engine/debugger/debugger.cs @@ -248,7 +248,7 @@ public bool UseDefaultProcessing /// public StartRunspaceDebugProcessingEventArgs(Runspace runspace) { - if (runspace == null) { throw new PSArgumentNullException("runspace"); } + if (runspace == null) { throw new PSArgumentNullException(nameof(runspace)); } Runspace = runspace; } @@ -274,7 +274,7 @@ public Runspace Runspace /// public ProcessRunspaceDebugEndEventArgs(Runspace runspace) { - if (runspace == null) { throw new PSArgumentNullException("runspace"); } + if (runspace == null) { throw new PSArgumentNullException(nameof(runspace)); } Runspace = runspace; } @@ -525,7 +525,7 @@ protected bool IsDebuggerBreakpointUpdatedEventSubscribed() /// protected void RaiseStartRunspaceDebugProcessingEvent(StartRunspaceDebugProcessingEventArgs args) { - if (args == null) { throw new PSArgumentNullException("args"); } + if (args == null) { throw new PSArgumentNullException(nameof(args)); } StartRunspaceDebugProcessing.SafeInvoke(this, args); } @@ -533,7 +533,7 @@ protected void RaiseStartRunspaceDebugProcessingEvent(StartRunspaceDebugProcessi /// protected void RaiseRunspaceProcessingCompletedEvent(ProcessRunspaceDebugEndEventArgs args) { - if (args == null) { throw new PSArgumentNullException("args"); } + if (args == null) { throw new PSArgumentNullException(nameof(args)); } RunspaceDebugProcessingCompleted.SafeInvoke(this, args); } @@ -2306,12 +2306,12 @@ public override DebuggerCommandResults ProcessCommand(PSCommand command, PSDataC { if (command == null) { - throw new PSArgumentNullException("command"); + throw new PSArgumentNullException(nameof(command)); } if (output == null) { - throw new PSArgumentNullException("output"); + throw new PSArgumentNullException(nameof(output)); } if (!DebuggerStopped) @@ -2915,7 +2915,7 @@ private Debugger GetRunspaceDebugger(int runspaceId) /// internal override void DebugJob(Job job, bool breakAll) { - if (job == null) { throw new PSArgumentNullException("job"); } + if (job == null) { throw new PSArgumentNullException(nameof(job)); } lock (_syncObject) { @@ -2989,7 +2989,7 @@ private bool TryAddDebugJob(Job job, bool breakAll) internal override void StopDebugJob(Job job) { // Parameter validation. - if (job == null) { throw new PSArgumentNullException("job"); } + if (job == null) { throw new PSArgumentNullException(nameof(job)); } SetInternalDebugMode(InternalDebugMode.Disabled); @@ -3036,7 +3036,7 @@ internal override void DebugRunspace(Runspace runspace, bool breakAll) { if (runspace == null) { - throw new PSArgumentNullException("runspace"); + throw new PSArgumentNullException(nameof(runspace)); } if (runspace.RunspaceStateInfo.State != RunspaceState.Opened) @@ -3079,7 +3079,7 @@ internal override void DebugRunspace(Runspace runspace, bool breakAll) /// Runspace. internal override void StopDebugRunspace(Runspace runspace) { - if (runspace == null) { throw new PSArgumentNullException("runspace"); } + if (runspace == null) { throw new PSArgumentNullException(nameof(runspace)); } SetInternalDebugMode(InternalDebugMode.Disabled); @@ -4225,7 +4225,7 @@ public NestedRunspaceDebugger( { if (runspace == null || runspace.Debugger == null) { - throw new PSArgumentNullException("runspace"); + throw new PSArgumentNullException(nameof(runspace)); } _runspace = runspace; @@ -4725,7 +4725,7 @@ public EmbeddedRunspaceDebugger( { if (rootDebugger == null) { - throw new PSArgumentNullException("rootDebugger"); + throw new PSArgumentNullException(nameof(rootDebugger)); } _command = command; @@ -5474,7 +5474,7 @@ public PSDebugContext(InvocationInfo invocationInfo, List breakpoint { if (breakpoints == null) { - throw new PSArgumentNullException("breakpoints"); + throw new PSArgumentNullException(nameof(breakpoints)); } this.InvocationInfo = invocationInfo; @@ -5526,7 +5526,7 @@ internal CallStackFrame(FunctionContext functionContext, InvocationInfo invocati { if (invocationInfo == null) { - throw new PSArgumentNullException("invocationInfo"); + throw new PSArgumentNullException(nameof(invocationInfo)); } if (functionContext != null) @@ -5682,7 +5682,7 @@ public static bool ShouldAddCommandToHistory(string command) { if (command == null) { - throw new PSArgumentNullException("command"); + throw new PSArgumentNullException(nameof(command)); } lock (s_noHistoryCommandNames) @@ -5700,12 +5700,12 @@ public static void StartMonitoringRunspace(Debugger debugger, PSMonitorRunspaceI { if (debugger == null) { - throw new PSArgumentNullException("debugger"); + throw new PSArgumentNullException(nameof(debugger)); } if (runspaceInfo == null) { - throw new PSArgumentNullException("runspaceInfo"); + throw new PSArgumentNullException(nameof(runspaceInfo)); } debugger.StartMonitoringRunspace(runspaceInfo); @@ -5720,12 +5720,12 @@ public static void EndMonitoringRunspace(Debugger debugger, PSMonitorRunspaceInf { if (debugger == null) { - throw new PSArgumentNullException("debugger"); + throw new PSArgumentNullException(nameof(debugger)); } if (runspaceInfo == null) { - throw new PSArgumentNullException("runspaceInfo"); + throw new PSArgumentNullException(nameof(runspaceInfo)); } debugger.EndMonitoringRunspace(runspaceInfo); @@ -5791,7 +5791,7 @@ protected PSMonitorRunspaceInfo( { if (runspace == null) { - throw new PSArgumentNullException("runspace"); + throw new PSArgumentNullException(nameof(runspace)); } Runspace = runspace; diff --git a/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs b/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs index e55f7618df6..8a0101ae802 100644 --- a/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs +++ b/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs @@ -241,7 +241,7 @@ internal bool InvokeCallbackOnThread(WaitCallback callback, object state) { if (callback == null) { - throw new PSArgumentNullException("callback"); + throw new PSArgumentNullException(nameof(callback)); } _invokeCallback = callback; diff --git a/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs b/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs index ba3a8c13b66..9fca84d4a33 100644 --- a/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs +++ b/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs @@ -38,7 +38,7 @@ class ChoiceDescription if (string.IsNullOrEmpty(label)) { // "label" is not localizable - throw PSTraceSource.NewArgumentException("label", DescriptionsStrings.NullOrEmptyErrorTemplate, "label"); + throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, "label"); } this.label = label; @@ -68,13 +68,13 @@ class ChoiceDescription if (string.IsNullOrEmpty(label)) { // "label" is not localizable - throw PSTraceSource.NewArgumentException("label", DescriptionsStrings.NullOrEmptyErrorTemplate, "label"); + throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, "label"); } if (helpMessage == null) { // "helpMessage" is not localizable - throw PSTraceSource.NewArgumentNullException("helpMessage"); + throw PSTraceSource.NewArgumentNullException(nameof(helpMessage)); } this.label = label; diff --git a/src/System.Management.Automation/engine/hostifaces/Command.cs b/src/System.Management.Automation/engine/hostifaces/Command.cs index 08f323d809a..b98e447563b 100644 --- a/src/System.Management.Automation/engine/hostifaces/Command.cs +++ b/src/System.Management.Automation/engine/hostifaces/Command.cs @@ -52,7 +52,7 @@ public Command(string command, bool isScript, bool useLocalScope) IsEndOfStatement = false; if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } CommandText = command; @@ -65,7 +65,7 @@ internal Command(string command, bool isScript, bool? useLocalScope) IsEndOfStatement = false; if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } CommandText = command; @@ -318,17 +318,17 @@ public void MergeMyResults(PipelineResultTypes myResult, PipelineResultTypes toR // Validate parameters. if (myResult == PipelineResultTypes.None || myResult == PipelineResultTypes.Output) { - throw PSTraceSource.NewArgumentException("myResult", RunspaceStrings.InvalidMyResultError); + throw PSTraceSource.NewArgumentException(nameof(myResult), RunspaceStrings.InvalidMyResultError); } if (myResult == PipelineResultTypes.Error && toResult != PipelineResultTypes.Output) { - throw PSTraceSource.NewArgumentException("toResult", RunspaceStrings.InvalidValueToResultError); + throw PSTraceSource.NewArgumentException(nameof(toResult), RunspaceStrings.InvalidValueToResultError); } if (toResult != PipelineResultTypes.Output && toResult != PipelineResultTypes.Null) { - throw PSTraceSource.NewArgumentException("toResult", RunspaceStrings.InvalidValueToResult); + throw PSTraceSource.NewArgumentException(nameof(toResult), RunspaceStrings.InvalidValueToResult); } // For V2 backwards compatibility. @@ -518,8 +518,8 @@ CommandOrigin origin case PSLanguageMode.NoLanguage: string message = StringUtil.Format(RunspaceStrings.UseLocalScopeNotAllowed, "UseLocalScope", - PSLanguageMode.RestrictedLanguage.ToString(), - PSLanguageMode.NoLanguage.ToString()); + nameof(PSLanguageMode.RestrictedLanguage), + nameof(PSLanguageMode.NoLanguage)); throw new RuntimeException(message); case PSLanguageMode.FullLanguage: // Interactive script commands are permitted in this mode... @@ -592,7 +592,7 @@ internal static Command FromPSObjectForRemoting(PSObject commandAsPSObject) { if (commandAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("commandAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(commandAsPSObject)); } string commandText = RemotingDecoder.GetPropertyValue(commandAsPSObject, RemoteDataNameStrings.CommandText); diff --git a/src/System.Management.Automation/engine/hostifaces/Connection.cs b/src/System.Management.Automation/engine/hostifaces/Connection.cs index 89d04fa515b..fef195ac1a2 100644 --- a/src/System.Management.Automation/engine/hostifaces/Connection.cs +++ b/src/System.Management.Automation/engine/hostifaces/Connection.cs @@ -333,7 +333,7 @@ internal RunspaceStateEventArgs(RunspaceStateInfo runspaceStateInfo) { if (runspaceStateInfo == null) { - throw PSTraceSource.NewArgumentNullException("runspaceStateInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(runspaceStateInfo)); } RunspaceStateInfo = runspaceStateInfo; @@ -1700,7 +1700,7 @@ public virtual void SetVariable(string name, object value) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } _runspace.SetVariable(name, value); @@ -1728,7 +1728,7 @@ public virtual object GetVariable(string name) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } if (name.Equals(string.Empty)) diff --git a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs index dd3544aa406..bd0f7943b54 100644 --- a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs +++ b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs @@ -40,7 +40,7 @@ protected RunspaceBase(PSHost host) { if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } InitialSessionState = InitialSessionState.CreateDefault(); @@ -66,12 +66,12 @@ protected RunspaceBase(PSHost host, InitialSessionState initialSessionState) { if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } if (initialSessionState == null) { - throw PSTraceSource.NewArgumentNullException("initialSessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } Host = host; @@ -104,12 +104,12 @@ protected RunspaceBase(PSHost host, InitialSessionState initialSessionState, boo { if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } if (initialSessionState == null) { - throw PSTraceSource.NewArgumentNullException("initialSessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } Host = host; @@ -535,7 +535,7 @@ public override Pipeline CreatePipeline(string command) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } return CoreCreatePipeline(command, false, false); @@ -556,7 +556,7 @@ public override Pipeline CreatePipeline(string command, bool addToHistory) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } return CoreCreatePipeline(command, addToHistory, false); @@ -590,7 +590,7 @@ public override Pipeline CreateNestedPipeline(string command, bool addToHistory) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } return CoreCreatePipeline(command, addToHistory, true); diff --git a/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs b/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs index b42d8d7198a..2021ae6abf9 100644 --- a/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs +++ b/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs @@ -62,7 +62,7 @@ public static Runspace CreateRunspace(PSHost host) { if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } return new LocalRunspace(host, InitialSessionState.CreateDefault()); @@ -85,7 +85,7 @@ public static Runspace CreateRunspace(InitialSessionState initialSessionState) { if (initialSessionState == null) { - throw PSTraceSource.NewArgumentNullException("initialSessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } PSHost host = new DefaultHost(CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture); @@ -116,12 +116,12 @@ public static Runspace CreateRunspace(PSHost host, InitialSessionState initialSe { if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } if (initialSessionState == null) { - throw PSTraceSource.NewArgumentNullException("initialSessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } return new LocalRunspace(host, initialSessionState); @@ -150,12 +150,12 @@ internal static Runspace CreateRunspaceFromSessionStateNoClone(PSHost host, Init { if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } if (initialSessionState == null) { - throw PSTraceSource.NewArgumentNullException("initialSessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } return new LocalRunspace(host, initialSessionState, true); diff --git a/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs b/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs index 1556d10aa55..545440a1574 100644 --- a/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs +++ b/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs @@ -43,7 +43,7 @@ public class if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException("name", DescriptionsStrings.NullOrEmptyErrorTemplate, "name"); + throw PSTraceSource.NewArgumentException(nameof(name), DescriptionsStrings.NullOrEmptyErrorTemplate, "name"); } this.name = name; @@ -76,7 +76,7 @@ public string Name { if (parameterType == null) { - throw PSTraceSource.NewArgumentNullException("parameterType"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterType)); } SetParameterTypeName(parameterType.Name); @@ -319,7 +319,7 @@ public string Name { if (string.IsNullOrEmpty(nameOfType)) { - throw PSTraceSource.NewArgumentException("nameOfType", DescriptionsStrings.NullOrEmptyErrorTemplate, "nameOfType"); + throw PSTraceSource.NewArgumentException(nameof(nameOfType), DescriptionsStrings.NullOrEmptyErrorTemplate, "nameOfType"); } parameterTypeName = nameOfType; @@ -339,7 +339,7 @@ public string Name { if (string.IsNullOrEmpty(fullNameOfType)) { - throw PSTraceSource.NewArgumentException("fullNameOfType", DescriptionsStrings.NullOrEmptyErrorTemplate, "fullNameOfType"); + throw PSTraceSource.NewArgumentException(nameof(fullNameOfType), DescriptionsStrings.NullOrEmptyErrorTemplate, "fullNameOfType"); } parameterTypeFullName = fullNameOfType; @@ -359,7 +359,7 @@ public string Name { if (string.IsNullOrEmpty(fullNameOfAssembly)) { - throw PSTraceSource.NewArgumentException("fullNameOfAssembly", DescriptionsStrings.NullOrEmptyErrorTemplate, "fullNameOfAssembly"); + throw PSTraceSource.NewArgumentException(nameof(fullNameOfAssembly), DescriptionsStrings.NullOrEmptyErrorTemplate, "fullNameOfAssembly"); } parameterAssemblyFullName = fullNameOfAssembly; diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index b6138df546c..e22aa0804eb 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -285,12 +285,12 @@ internal HistoryInfo[] GetEntries(long id, long count, SwitchParameter newest) if (count < -1) { - throw PSTraceSource.NewArgumentOutOfRangeException("count", count); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(count), count); } if (newest.ToString() == null) { - throw PSTraceSource.NewArgumentNullException("newest"); + throw PSTraceSource.NewArgumentNullException(nameof(newest)); } if (count == -1 || count > _countEntriesAdded || count > _countEntriesInBuffer) @@ -467,12 +467,12 @@ internal HistoryInfo[] GetEntries(WildcardPattern wildcardpattern, long count, S { if (count < -1) { - throw PSTraceSource.NewArgumentOutOfRangeException("count", count); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(count), count); } if (newest.ToString() == null) { - throw PSTraceSource.NewArgumentNullException("newest"); + throw PSTraceSource.NewArgumentNullException(nameof(newest)); } if (count > _countEntriesAdded || count == -1) @@ -560,7 +560,7 @@ internal void ClearEntry(long id) { if (id < 0) { - throw PSTraceSource.NewArgumentOutOfRangeException("id", id); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(id), id); } // no entries are present to clear if (_countEntriesInBuffer == 0) @@ -610,7 +610,7 @@ private long Add(HistoryInfo entry) { if (entry == null) { - throw PSTraceSource.NewArgumentNullException("entry"); + throw PSTraceSource.NewArgumentNullException(nameof(entry)); } _buffer[GetIndexForNewEntry()] = entry; @@ -638,7 +638,7 @@ private HistoryInfo CoreGetEntry(long id) { if (id <= 0) { - throw PSTraceSource.NewArgumentOutOfRangeException("id", id); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(id), id); } if (_countEntriesInBuffer == 0) diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index 66f0d841bfb..ecc4780c284 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -800,12 +800,12 @@ public static Collection InvokeOnRunspace(PSCommand command, Runspace { if (command == null) { - throw new PSArgumentNullException("command"); + throw new PSArgumentNullException(nameof(command)); } if (runspace == null) { - throw new PSArgumentNullException("runspace"); + throw new PSArgumentNullException(nameof(runspace)); } if ((runspace.Debugger != null) && runspace.Debugger.InBreakpoint) diff --git a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs index f0185900bbb..1e61ca236bd 100644 --- a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs @@ -27,7 +27,7 @@ class InternalHostUserInterface : PSHostUserInterface, IHostUISupportsMultipleCh Dbg.Assert(parentHost != null, "parent may not be null"); if (parentHost == null) { - throw PSTraceSource.NewArgumentNullException("parentHost"); + throw PSTraceSource.NewArgumentNullException(nameof(parentHost)); } _parent = parentHost; @@ -414,7 +414,7 @@ internal void WriteDebugInfoBuffers(DebugRecord record) throw ense; default: Dbg.Assert(false, "all preferences should be checked"); - throw PSTraceSource.NewArgumentException("preference", + throw PSTraceSource.NewArgumentException(nameof(preference), InternalHostUserInterfaceStrings.UnsupportedPreferenceError, preference); // break; } @@ -546,7 +546,7 @@ public override { if (record == null) { - throw PSTraceSource.NewArgumentNullException("record"); + throw PSTraceSource.NewArgumentNullException(nameof(record)); } // Write to Information Buffers @@ -732,12 +732,12 @@ public override { if (descriptions == null) { - throw PSTraceSource.NewArgumentNullException("descriptions"); + throw PSTraceSource.NewArgumentNullException(nameof(descriptions)); } if (descriptions.Count < 1) { - throw PSTraceSource.NewArgumentException("descriptions", InternalHostUserInterfaceStrings.PromptEmptyDescriptionsError, "descriptions"); + throw PSTraceSource.NewArgumentException(nameof(descriptions), InternalHostUserInterfaceStrings.PromptEmptyDescriptionsError, "descriptions"); } if (_externalUI == null) @@ -898,12 +898,12 @@ private Collection EmulatePromptForMultipleChoice(string caption, if (choices == null) { - throw PSTraceSource.NewArgumentNullException("choices"); + throw PSTraceSource.NewArgumentNullException(nameof(choices)); } if (choices.Count == 0) { - throw PSTraceSource.NewArgumentException("choices", + throw PSTraceSource.NewArgumentException(nameof(choices), InternalHostUserInterfaceStrings.EmptyChoicesError, "choices"); } diff --git a/src/System.Management.Automation/engine/hostifaces/ListModifier.cs b/src/System.Management.Automation/engine/hostifaces/ListModifier.cs index bc25d928ef3..191a5309cc7 100644 --- a/src/System.Management.Automation/engine/hostifaces/ListModifier.cs +++ b/src/System.Management.Automation/engine/hostifaces/ListModifier.cs @@ -88,7 +88,7 @@ public PSListModifier(Hashtable hash) { if (hash == null) { - throw PSTraceSource.NewArgumentNullException("hash"); + throw PSTraceSource.NewArgumentNullException(nameof(hash)); } _itemsToAdd = new Collection(); @@ -106,7 +106,7 @@ public PSListModifier(Hashtable hash) if (!isAdd && !isRemove && !isReplace) { - throw PSTraceSource.NewArgumentException("hash", PSListModifierStrings.ListModifierDisallowedKey, key); + throw PSTraceSource.NewArgumentException(nameof(hash), PSListModifierStrings.ListModifierDisallowedKey, key); } Collection collection; @@ -138,7 +138,7 @@ public PSListModifier(Hashtable hash) } else { - throw PSTraceSource.NewArgumentException("hash", PSListModifierStrings.ListModifierDisallowedKey, entry.Key); + throw PSTraceSource.NewArgumentException(nameof(hash), PSListModifierStrings.ListModifierDisallowedKey, entry.Key); } } } @@ -181,7 +181,7 @@ public void ApplyTo(IList collectionToUpdate) { if (collectionToUpdate == null) { - throw PSTraceSource.NewArgumentNullException("collectionToUpdate"); + throw PSTraceSource.NewArgumentNullException(nameof(collectionToUpdate)); } if (_replacementItems.Count > 0) @@ -214,7 +214,7 @@ public void ApplyTo(object collectionToUpdate) { if (collectionToUpdate == null) { - throw new ArgumentNullException("collectionToUpdate"); + throw new ArgumentNullException(nameof(collectionToUpdate)); } collectionToUpdate = PSObject.Base(collectionToUpdate); diff --git a/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs b/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs index f924985fb5c..e63fc85e614 100644 --- a/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs +++ b/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs @@ -1592,7 +1592,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs index 48ab16c579a..da0877747de 100644 --- a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs +++ b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs @@ -1341,7 +1341,7 @@ internal void Push(PipelineProcessor item) { if (item == null) { - throw PSTraceSource.NewArgumentNullException("item"); + throw PSTraceSource.NewArgumentNullException(nameof(item)); } lock (_syncRoot) diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs index e107054326e..79f4bcff66a 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs @@ -794,13 +794,13 @@ public int Bottom if (right < left) { // "right" and "left" are not localizable - throw PSTraceSource.NewArgumentException("right", MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "right", "left"); + throw PSTraceSource.NewArgumentException(nameof(right), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "right", "left"); } if (bottom < top) { // "bottom" and "top" are not localizable - throw PSTraceSource.NewArgumentException("bottom", MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "bottom", "top"); + throw PSTraceSource.NewArgumentException(nameof(bottom), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "bottom", "top"); } this.left = left; @@ -1681,7 +1681,7 @@ int offset { if (source == null) { - throw PSTraceSource.NewArgumentNullException("source"); + throw PSTraceSource.NewArgumentNullException(nameof(source)); } // this implementation is inefficient @@ -1720,7 +1720,7 @@ string source { if (source == null) { - throw PSTraceSource.NewArgumentNullException("source"); + throw PSTraceSource.NewArgumentNullException(nameof(source)); } return source.Length; @@ -1807,7 +1807,7 @@ char source if (contents == null) { - throw PSTraceSource.NewArgumentNullException("contents"); + throw PSTraceSource.NewArgumentNullException(nameof(contents)); } byte[][] charLengths = new byte[contents.Length][]; @@ -1835,7 +1835,7 @@ char source if (maxStringLengthInBufferCells <= 0) { - throw PSTraceSource.NewArgumentException("contents", MshHostRawUserInterfaceStrings.AllNullOrEmptyStringsErrorTemplate); + throw PSTraceSource.NewArgumentException(nameof(contents), MshHostRawUserInterfaceStrings.AllNullOrEmptyStringsErrorTemplate); } BufferCell[,] results = new BufferCell[contents.Length, maxStringLengthInBufferCells]; @@ -1920,14 +1920,14 @@ char source if (width <= 0) { // "width" is not localizable - throw PSTraceSource.NewArgumentOutOfRangeException("width", width, + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(width), width, MshHostRawUserInterfaceStrings.NonPositiveNumberErrorTemplate, "width"); } if (height <= 0) { // "height" is not localizable - throw PSTraceSource.NewArgumentOutOfRangeException("height", height, + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(height), height, MshHostRawUserInterfaceStrings.NonPositiveNumberErrorTemplate, "height"); } diff --git a/src/System.Management.Automation/engine/hostifaces/PSCommand.cs b/src/System.Management.Automation/engine/hostifaces/PSCommand.cs index 9da8f7c9081..781e53eaf51 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSCommand.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSCommand.cs @@ -133,7 +133,7 @@ public PSCommand AddCommand(string cmdlet, bool useLocalScope) { if (cmdlet == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdlet)); } if (_owner != null) @@ -175,7 +175,7 @@ public PSCommand AddScript(string script) { if (script == null) { - throw PSTraceSource.NewArgumentNullException("script"); + throw PSTraceSource.NewArgumentNullException(nameof(script)); } if (_owner != null) @@ -220,7 +220,7 @@ public PSCommand AddScript(string script, bool useLocalScope) { if (script == null) { - throw PSTraceSource.NewArgumentNullException("script"); + throw PSTraceSource.NewArgumentNullException(nameof(script)); } if (_owner != null) @@ -258,7 +258,7 @@ public PSCommand AddCommand(Command command) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } if (_owner != null) diff --git a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs index 5d6fc8578ca..51d74dcc269 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs @@ -333,14 +333,14 @@ protected PSDataCollection(SerializationInfo info, StreamingContext context) { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } IList listToUse = info.GetValue("Data", typeof(IList)) as IList; if (listToUse == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } _data = listToUse; @@ -664,7 +664,7 @@ public T this[int index] { if ((index < 0) || (index >= _data.Count)) { - throw PSTraceSource.NewArgumentOutOfRangeException("index", index, + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(index), index, PSDataBufferStrings.IndexOutOfRange, 0, _data.Count - 1); } @@ -738,7 +738,7 @@ public void RemoveAt(int index) { if ((index < 0) || (index >= _data.Count)) { - throw PSTraceSource.NewArgumentOutOfRangeException("index", index, + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(index), index, PSDataBufferStrings.IndexOutOfRange, 0, _data.Count - 1); } @@ -1299,7 +1299,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } info.AddValue("Data", _data); @@ -1514,7 +1514,7 @@ internal void InternalAddRange(Guid psInstanceId, ICollection collection) { if (collection == null) { - throw PSTraceSource.NewArgumentNullException("collection"); + throw PSTraceSource.NewArgumentNullException(nameof(collection)); } int index = -1; @@ -1631,12 +1631,12 @@ private static void VerifyValueType(object value) { if (typeof(T).IsValueType) { - throw PSTraceSource.NewArgumentNullException("value", PSDataBufferStrings.ValueNullReference); + throw PSTraceSource.NewArgumentNullException(nameof(value), PSDataBufferStrings.ValueNullReference); } } else if (!(value is T)) { - throw PSTraceSource.NewArgumentException("value", PSDataBufferStrings.CannotConvertToGenericType, + throw PSTraceSource.NewArgumentException(nameof(value), PSDataBufferStrings.CannotConvertToGenericType, value.GetType().FullName, typeof(T).FullName); } diff --git a/src/System.Management.Automation/engine/hostifaces/PSTask.cs b/src/System.Management.Automation/engine/hostifaces/PSTask.cs index fe42bd55d24..6bf8a74b839 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSTask.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSTask.cs @@ -1191,7 +1191,7 @@ public PSTaskChildDebugger( { if (debugger == null) { - throw new PSArgumentNullException("debugger"); + throw new PSArgumentNullException(nameof(debugger)); } _wrappedDebugger = debugger; diff --git a/src/System.Management.Automation/engine/hostifaces/Parameter.cs b/src/System.Management.Automation/engine/hostifaces/Parameter.cs index 3ffb3d22f97..3f7d072318a 100644 --- a/src/System.Management.Automation/engine/hostifaces/Parameter.cs +++ b/src/System.Management.Automation/engine/hostifaces/Parameter.cs @@ -33,7 +33,7 @@ public CommandParameter(string name) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } } @@ -51,7 +51,7 @@ public CommandParameter(string name, object value) { if (string.IsNullOrWhiteSpace(name)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } Name = name; @@ -90,7 +90,7 @@ internal static CommandParameter FromCommandParameterInternal(CommandParameterIn { if (internalParameter == null) { - throw PSTraceSource.NewArgumentNullException("internalParameter"); + throw PSTraceSource.NewArgumentNullException(nameof(internalParameter)); } // we want the name to preserve 1) dashes, 2) colons, 3) followed-by-space information @@ -125,7 +125,7 @@ internal static CommandParameterInternal ToCommandParameterInternal(CommandParam { if (publicParameter == null) { - throw PSTraceSource.NewArgumentNullException("publicParameter"); + throw PSTraceSource.NewArgumentNullException(nameof(publicParameter)); } string name = publicParameter.Name; @@ -211,7 +211,7 @@ internal static CommandParameter FromPSObjectForRemoting(PSObject parameterAsPSO { if (parameterAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("parameterAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(parameterAsPSObject)); } string name = RemotingDecoder.GetPropertyValue(parameterAsPSObject, RemoteDataNameStrings.ParameterName); diff --git a/src/System.Management.Automation/engine/hostifaces/Pipeline.cs b/src/System.Management.Automation/engine/hostifaces/Pipeline.cs index 7c20c17f194..0a584c6fc36 100644 --- a/src/System.Management.Automation/engine/hostifaces/Pipeline.cs +++ b/src/System.Management.Automation/engine/hostifaces/Pipeline.cs @@ -305,7 +305,7 @@ internal Pipeline(Runspace runspace, CommandCollection command) { if (runspace == null) { - PSTraceSource.NewArgumentNullException("runspace"); + PSTraceSource.NewArgumentNullException(nameof(runspace)); } // This constructor is used only internally. // Caller should make sure the input is valid diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 0bb95d30d55..646f289076c 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -1169,7 +1169,7 @@ public PowerShell AddCommand(CommandInfo commandInfo) { if (commandInfo == null) { - throw PSTraceSource.NewArgumentNullException("commandInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(commandInfo)); } Command cmd = new Command(commandInfo); @@ -1292,7 +1292,7 @@ public PowerShell AddParameters(IList parameters) { if (parameters == null) { - throw PSTraceSource.NewArgumentNullException("parameters"); + throw PSTraceSource.NewArgumentNullException(nameof(parameters)); } if (_psCommand.Commands.Count == 0) @@ -1340,7 +1340,7 @@ public PowerShell AddParameters(IDictionary parameters) { if (parameters == null) { - throw PSTraceSource.NewArgumentNullException("parameters"); + throw PSTraceSource.NewArgumentNullException(nameof(parameters)); } if (_psCommand.Commands.Count == 0) @@ -1356,7 +1356,7 @@ public PowerShell AddParameters(IDictionary parameters) if (parameterName == null) { - throw PSTraceSource.NewArgumentException("parameters", PowerShellStrings.KeyMustBeString); + throw PSTraceSource.NewArgumentException(nameof(parameters), PowerShellStrings.KeyMustBeString); } _psCommand.AddParameter(parameterName, entry.Value); @@ -2727,7 +2727,7 @@ public void Invoke(IEnumerable input, IList output, PSInvocationSettings s { if (output == null) { - throw PSTraceSource.NewArgumentNullException("output"); + throw PSTraceSource.NewArgumentNullException(nameof(output)); } // use the above collection as the data store. PSDataCollection listToWriteTo = new PSDataCollection(output); @@ -2798,7 +2798,7 @@ public void Invoke(PSDataCollection input, PSDataCollec { if (output == null) { - throw PSTraceSource.NewArgumentNullException("output"); + throw PSTraceSource.NewArgumentNullException(nameof(output)); } CoreInvoke(input, output, settings); @@ -3034,7 +3034,7 @@ public IAsyncResult BeginInvoke(PSDataCollection input, { if (output == null) { - throw PSTraceSource.NewArgumentNullException("output"); + throw PSTraceSource.NewArgumentNullException(nameof(output)); } DetermineIsBatching(); @@ -3649,7 +3649,7 @@ public PSDataCollection EndInvoke(IAsyncResult asyncResult) if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } PowerShellAsyncResult psAsyncResult = asyncResult as PowerShellAsyncResult; @@ -3658,7 +3658,7 @@ public PSDataCollection EndInvoke(IAsyncResult asyncResult) (psAsyncResult.OwnerId != InstanceId) || (psAsyncResult.IsAssociatedWithAsyncInvoke != true)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), PowerShellStrings.AsyncResultNotOwned, "IAsyncResult", "BeginInvoke"); } @@ -3752,7 +3752,7 @@ public void EndStop(IAsyncResult asyncResult) { if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } PowerShellAsyncResult psAsyncResult = asyncResult as PowerShellAsyncResult; @@ -3761,7 +3761,7 @@ public void EndStop(IAsyncResult asyncResult) (psAsyncResult.OwnerId != InstanceId) || (psAsyncResult.IsAssociatedWithAsyncInvoke != false)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), PowerShellStrings.AsyncResultNotOwned, "IAsyncResult", "BeginStop"); } @@ -5720,7 +5720,7 @@ internal static PowerShell FromPSObjectForRemoting(PSObject powerShellAsPSObject { if (powerShellAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("powerShellAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(powerShellAsPSObject)); } Collection extraCommands = null; @@ -6153,12 +6153,12 @@ internal PowerShellStopper(ExecutionContext context, PowerShell powerShell) { if (context == null) { - throw new ArgumentNullException("context"); + throw new ArgumentNullException(nameof(context)); } if (powerShell == null) { - throw new ArgumentNullException("powerShell"); + throw new ArgumentNullException(nameof(powerShell)); } _powerShell = powerShell; diff --git a/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs b/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs index 49950ac0fa1..aa4252cfcb1 100644 --- a/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs +++ b/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs @@ -76,7 +76,7 @@ public RunspacePoolInternal(int minRunspaces, { if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } this.host = host; @@ -121,12 +121,12 @@ public RunspacePoolInternal(int minRunspaces, { if (initialSessionState == null) { - throw PSTraceSource.NewArgumentNullException("initialSessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } if (host == null) { - throw PSTraceSource.NewArgumentNullException("host"); + throw PSTraceSource.NewArgumentNullException(nameof(host)); } _initialSessionState = initialSessionState.Clone(); @@ -154,17 +154,17 @@ protected RunspacePoolInternal(int minRunspaces, int maxRunspaces) { if (maxRunspaces < 1) { - throw PSTraceSource.NewArgumentException("maxRunspaces", RunspacePoolStrings.MaxPoolLessThan1); + throw PSTraceSource.NewArgumentException(nameof(maxRunspaces), RunspacePoolStrings.MaxPoolLessThan1); } if (minRunspaces < 1) { - throw PSTraceSource.NewArgumentException("minRunspaces", RunspacePoolStrings.MinPoolLessThan1); + throw PSTraceSource.NewArgumentException(nameof(minRunspaces), RunspacePoolStrings.MinPoolLessThan1); } if (minRunspaces > maxRunspaces) { - throw PSTraceSource.NewArgumentException("minRunspaces", RunspacePoolStrings.MinPoolGreaterThanMaxPool); + throw PSTraceSource.NewArgumentException(nameof(minRunspaces), RunspacePoolStrings.MinPoolGreaterThanMaxPool); } maxPoolSz = maxRunspaces; @@ -618,7 +618,7 @@ public void EndOpen(IAsyncResult asyncResult) { if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } RunspacePoolAsyncResult rsAsyncResult = asyncResult as RunspacePoolAsyncResult; @@ -627,7 +627,7 @@ public void EndOpen(IAsyncResult asyncResult) (rsAsyncResult.OwnerId != instanceId) || (!rsAsyncResult.IsAssociatedWithAsyncOpen)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), RunspacePoolStrings.AsyncResultNotOwned, "IAsyncResult", "BeginOpen"); @@ -685,7 +685,7 @@ public virtual void EndClose(IAsyncResult asyncResult) { if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } RunspacePoolAsyncResult rsAsyncResult = asyncResult as RunspacePoolAsyncResult; @@ -694,7 +694,7 @@ public virtual void EndClose(IAsyncResult asyncResult) (rsAsyncResult.OwnerId != instanceId) || (rsAsyncResult.IsAssociatedWithAsyncOpen)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), RunspacePoolStrings.AsyncResultNotOwned, "IAsyncResult", "BeginClose"); @@ -754,7 +754,7 @@ public void ReleaseRunspace(Runspace runspace) { if (runspace == null) { - throw PSTraceSource.NewArgumentNullException("runspace"); + throw PSTraceSource.NewArgumentNullException(nameof(runspace)); } AssertPoolIsOpen(); @@ -893,7 +893,7 @@ internal void CancelGetRunspace(IAsyncResult asyncResult) { if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } GetRunspaceAsyncResult grsAsyncResult = @@ -901,7 +901,7 @@ internal void CancelGetRunspace(IAsyncResult asyncResult) if ((grsAsyncResult == null) || (grsAsyncResult.OwnerId != instanceId)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), RunspacePoolStrings.AsyncResultNotOwned, "IAsyncResult", "BeginGetRunspace"); @@ -932,7 +932,7 @@ internal Runspace EndGetRunspace(IAsyncResult asyncResult) { if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } GetRunspaceAsyncResult grsAsyncResult = @@ -940,7 +940,7 @@ internal Runspace EndGetRunspace(IAsyncResult asyncResult) if ((grsAsyncResult == null) || (grsAsyncResult.OwnerId != instanceId)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), RunspacePoolStrings.AsyncResultNotOwned, "IAsyncResult", "BeginGetRunspace"); diff --git a/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs b/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs index fbc2276f693..df15ce6313e 100644 --- a/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs +++ b/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs @@ -128,7 +128,7 @@ protected PipelineBase(PipelineBase pipeline) // NTRAID#Windows Out Of Band Releases-915851-2005/09/13 if (pipeline == null) { - throw PSTraceSource.NewArgumentNullException("pipeline"); + throw PSTraceSource.NewArgumentNullException(nameof(pipeline)); } if (pipeline._disposed) @@ -997,7 +997,7 @@ private void Initialize(Runspace runspace, string command, bool addToHistory, bo if (addToHistory && command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } if (command != null) diff --git a/src/System.Management.Automation/engine/lang/interface/PSParser.cs b/src/System.Management.Automation/engine/lang/interface/PSParser.cs index 0a4f93e2d5a..2b6886dbce6 100644 --- a/src/System.Management.Automation/engine/lang/interface/PSParser.cs +++ b/src/System.Management.Automation/engine/lang/interface/PSParser.cs @@ -147,7 +147,7 @@ private Collection Errors public static Collection Tokenize(string script, out Collection errors) { if (script == null) - throw PSTraceSource.NewArgumentNullException("script"); + throw PSTraceSource.NewArgumentNullException(nameof(script)); PSParser psParser = new PSParser(); @@ -174,7 +174,7 @@ public static Collection Tokenize(string script, out Collection Tokenize(object[] script, out Collection errors) { if (script == null) - throw PSTraceSource.NewArgumentNullException("script"); + throw PSTraceSource.NewArgumentNullException(nameof(script)); StringBuilder sb = new StringBuilder(); foreach (object obj in script) diff --git a/src/System.Management.Automation/engine/lang/parserutils.cs b/src/System.Management.Automation/engine/lang/parserutils.cs index 180a1fe0f69..d2203f8b90e 100644 --- a/src/System.Management.Automation/engine/lang/parserutils.cs +++ b/src/System.Management.Automation/engine/lang/parserutils.cs @@ -1810,7 +1810,7 @@ internal static RuntimeException NewInterpreterExceptionWithInnerException(objec { // errToken may be null if (string.IsNullOrEmpty(resourceIdAndErrorId)) - throw PSTraceSource.NewArgumentException("resourceIdAndErrorId"); + throw PSTraceSource.NewArgumentException(nameof(resourceIdAndErrorId)); // innerException may be null // args may be null or empty diff --git a/src/System.Management.Automation/engine/parser/Compiler.cs b/src/System.Management.Automation/engine/parser/Compiler.cs index 776691a68f0..e787c9e9f9b 100644 --- a/src/System.Management.Automation/engine/parser/Compiler.cs +++ b/src/System.Management.Automation/engine/parser/Compiler.cs @@ -2281,7 +2281,7 @@ private Expression CaptureAstResults( result = resultList; break; default: - throw new ArgumentOutOfRangeException("context"); + throw new ArgumentOutOfRangeException(nameof(context)); } finallyExprs.Add(Expression.Assign(s_getCurrentPipe, oldPipe)); diff --git a/src/System.Management.Automation/engine/parser/SafeValues.cs b/src/System.Management.Automation/engine/parser/SafeValues.cs index abe3b95b933..d91ec35356d 100644 --- a/src/System.Management.Automation/engine/parser/SafeValues.cs +++ b/src/System.Management.Automation/engine/parser/SafeValues.cs @@ -529,7 +529,7 @@ public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) var target = indexExpressionAst.Target.Accept(this); if (index == null || target == null) { - throw new ArgumentNullException("indexExpressionAst"); + throw new ArgumentNullException(nameof(indexExpressionAst)); } return GetIndexedValueFromTarget(target, index); diff --git a/src/System.Management.Automation/engine/parser/ast.cs b/src/System.Management.Automation/engine/parser/ast.cs index f135fadfd54..8877109a51c 100644 --- a/src/System.Management.Automation/engine/parser/ast.cs +++ b/src/System.Management.Automation/engine/parser/ast.cs @@ -93,7 +93,7 @@ protected Ast(IScriptExtent extent) { if (extent == null) { - throw PSTraceSource.NewArgumentNullException("extent"); + throw PSTraceSource.NewArgumentNullException(nameof(extent)); } this.Extent = extent; @@ -119,7 +119,7 @@ public object Visit(ICustomAstVisitor astVisitor) { if (astVisitor == null) { - throw PSTraceSource.NewArgumentNullException("astVisitor"); + throw PSTraceSource.NewArgumentNullException(nameof(astVisitor)); } return this.Accept(astVisitor); @@ -133,7 +133,7 @@ public void Visit(AstVisitor astVisitor) { if (astVisitor == null) { - throw PSTraceSource.NewArgumentNullException("astVisitor"); + throw PSTraceSource.NewArgumentNullException(nameof(astVisitor)); } this.InternalVisit(astVisitor); @@ -149,7 +149,7 @@ public IEnumerable FindAll(Func predicate, bool searchNestedScri { if (predicate == null) { - throw PSTraceSource.NewArgumentNullException("predicate"); + throw PSTraceSource.NewArgumentNullException(nameof(predicate)); } return AstSearcher.FindAll(this, predicate, searchNestedScriptBlocks); @@ -165,7 +165,7 @@ public Ast Find(Func predicate, bool searchNestedScriptBlocks) { if (predicate == null) { - throw PSTraceSource.NewArgumentNullException("predicate"); + throw PSTraceSource.NewArgumentNullException(nameof(predicate)); } return AstSearcher.FindFirst(this, predicate, searchNestedScriptBlocks); @@ -449,7 +449,7 @@ internal ErrorStatementAst(IScriptExtent extent, Token kind, IEnumerable ne { if (kind == null) { - throw PSTraceSource.NewArgumentNullException("kind"); + throw PSTraceSource.NewArgumentNullException(nameof(kind)); } Kind = kind; @@ -465,7 +465,7 @@ internal ErrorStatementAst(IScriptExtent extent, Token kind, IEnumerable using if (statements == null) { - throw PSTraceSource.NewArgumentNullException("statements"); + throw PSTraceSource.NewArgumentNullException(nameof(statements)); } if (paramBlock != null) @@ -1753,12 +1753,12 @@ public NamedBlockAst(IScriptExtent extent, TokenKind blockName, StatementBlockAs if (!blockName.HasTrait(TokenFlags.ScriptBlockBlockName) || (unnamed && (blockName == TokenKind.Begin || blockName == TokenKind.Dynamicparam))) { - throw PSTraceSource.NewArgumentException("blockName"); + throw PSTraceSource.NewArgumentException(nameof(blockName)); } if (statementBlock == null) { - throw PSTraceSource.NewArgumentNullException("statementBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(statementBlock)); } this.Unnamed = unnamed; @@ -1901,12 +1901,12 @@ public NamedAttributeArgumentAst(IScriptExtent extent, string argumentName, Expr { if (string.IsNullOrEmpty(argumentName)) { - throw PSTraceSource.NewArgumentNullException("argumentName"); + throw PSTraceSource.NewArgumentNullException(nameof(argumentName)); } if (argument == null) { - throw PSTraceSource.NewArgumentNullException("argument"); + throw PSTraceSource.NewArgumentNullException(nameof(argument)); } this.Argument = argument; @@ -1979,7 +1979,7 @@ protected AttributeBaseAst(IScriptExtent extent, ITypeName typeName) { if (typeName == null) { - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); } this.TypeName = typeName; @@ -2190,7 +2190,7 @@ public ParameterAst(IScriptExtent extent, { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } if (attributes != null) @@ -2533,7 +2533,7 @@ public TypeDefinitionAst(IScriptExtent extent, string name, IEnumerable scriptBlockTokenC { if (scriptBlockTokenCache == null) { - throw new ArgumentNullException("scriptBlockTokenCache"); + throw new ArgumentNullException(nameof(scriptBlockTokenCache)); } var commentTokens = HelpCommentsParser.GetHelpCommentTokens(this, scriptBlockTokenCache); @@ -3890,7 +3890,7 @@ public IfStatementAst(IScriptExtent extent, IEnumerable clauses, State { if (clauses == null || !clauses.Any()) { - throw PSTraceSource.NewArgumentException("clauses"); + throw PSTraceSource.NewArgumentException(nameof(clauses)); } this.Clauses = new ReadOnlyCollection(clauses.ToArray()); @@ -3995,7 +3995,7 @@ public DataStatementAst(IScriptExtent extent, { if (body == null) { - throw PSTraceSource.NewArgumentNullException("body"); + throw PSTraceSource.NewArgumentNullException(nameof(body)); } if (string.IsNullOrWhiteSpace(variableName)) @@ -4137,7 +4137,7 @@ protected LoopStatementAst(IScriptExtent extent, string label, PipelineBaseAst c { if (body == null) { - throw PSTraceSource.NewArgumentNullException("body"); + throw PSTraceSource.NewArgumentNullException(nameof(body)); } this.Body = body; @@ -4404,7 +4404,7 @@ public DoWhileStatementAst(IScriptExtent extent, string label, PipelineBaseAst c { if (condition == null) { - throw PSTraceSource.NewArgumentNullException("condition"); + throw PSTraceSource.NewArgumentNullException(nameof(condition)); } } @@ -4460,7 +4460,7 @@ public DoUntilStatementAst(IScriptExtent extent, string label, PipelineBaseAst c { if (condition == null) { - throw PSTraceSource.NewArgumentNullException("condition"); + throw PSTraceSource.NewArgumentNullException(nameof(condition)); } } @@ -4516,7 +4516,7 @@ public WhileStatementAst(IScriptExtent extent, string label, PipelineBaseAst con { if (condition == null) { - throw PSTraceSource.NewArgumentNullException("condition"); + throw PSTraceSource.NewArgumentNullException(nameof(condition)); } } @@ -4636,7 +4636,7 @@ public SwitchStatementAst(IScriptExtent extent, { // Must specify either clauses or default. If neither, just complain about clauses as that's the most likely // invalid argument. - throw PSTraceSource.NewArgumentException("clauses"); + throw PSTraceSource.NewArgumentException(nameof(clauses)); } this.Flags = flags; @@ -4752,7 +4752,7 @@ public CatchClauseAst(IScriptExtent extent, IEnumerable catch { if (body == null) { - throw PSTraceSource.NewArgumentNullException("body"); + throw PSTraceSource.NewArgumentNullException(nameof(body)); } if (catchTypes != null) @@ -4855,13 +4855,13 @@ public TryStatementAst(IScriptExtent extent, { if (body == null) { - throw PSTraceSource.NewArgumentNullException("body"); + throw PSTraceSource.NewArgumentNullException(nameof(body)); } if ((catchClauses == null || !catchClauses.Any()) && @finally == null) { // If no catches and no finally, just complain about catchClauses as that's the most likely invalid argument. - throw PSTraceSource.NewArgumentException("catchClauses"); + throw PSTraceSource.NewArgumentException(nameof(catchClauses)); } this.Body = body; @@ -4964,7 +4964,7 @@ public TrapStatementAst(IScriptExtent extent, TypeConstraintAst trapType, Statem { if (body == null) { - throw PSTraceSource.NewArgumentNullException("body"); + throw PSTraceSource.NewArgumentNullException(nameof(body)); } if (trapType != null) @@ -5520,7 +5520,7 @@ public PipelineAst(IScriptExtent extent, IEnumerable pipelineEle { if (pipelineElements == null || !pipelineElements.Any()) { - throw PSTraceSource.NewArgumentException("pipelineElements"); + throw PSTraceSource.NewArgumentException(nameof(pipelineElements)); } this.Background = background; @@ -5557,7 +5557,7 @@ public PipelineAst(IScriptExtent extent, CommandBaseAst commandAst, bool backgro { if (commandAst == null) { - throw PSTraceSource.NewArgumentNullException("commandAst"); + throw PSTraceSource.NewArgumentNullException(nameof(commandAst)); } this.Background = background; @@ -5830,12 +5830,12 @@ public CommandAst(IScriptExtent extent, { if (commandElements == null || !commandElements.Any()) { - throw PSTraceSource.NewArgumentException("commandElements"); + throw PSTraceSource.NewArgumentException(nameof(commandElements)); } if (invocationOperator != TokenKind.Dot && invocationOperator != TokenKind.Ampersand && invocationOperator != TokenKind.Unknown) { - throw PSTraceSource.NewArgumentException("invocationOperator"); + throw PSTraceSource.NewArgumentException(nameof(invocationOperator)); } this.CommandElements = new ReadOnlyCollection(commandElements.ToArray()); @@ -5951,7 +5951,7 @@ public CommandExpressionAst(IScriptExtent extent, { if (expression == null) { - throw PSTraceSource.NewArgumentNullException("expression"); + throw PSTraceSource.NewArgumentNullException(nameof(expression)); } this.Expression = expression; @@ -6144,7 +6144,7 @@ public FileRedirectionAst(IScriptExtent extent, RedirectionStream stream, Expres { if (file == null) { - throw PSTraceSource.NewArgumentNullException("file"); + throw PSTraceSource.NewArgumentNullException(nameof(file)); } this.Location = file; @@ -6220,7 +6220,7 @@ public AssignmentStatementAst(IScriptExtent extent, ExpressionAst left, TokenKin if ((@operator.GetTraits() & TokenFlags.AssignmentOperator) == 0) { - throw PSTraceSource.NewArgumentException("operator"); + throw PSTraceSource.NewArgumentException(nameof(@operator)); } // If the assignment is just an expression and the expression is not backgrounded then @@ -6361,17 +6361,17 @@ public ConfigurationDefinitionAst(IScriptExtent extent, { if (extent == null) { - throw PSTraceSource.NewArgumentNullException("extent"); + throw PSTraceSource.NewArgumentNullException(nameof(extent)); } if (body == null) { - throw PSTraceSource.NewArgumentNullException("body"); + throw PSTraceSource.NewArgumentNullException(nameof(body)); } if (instanceName == null) { - throw PSTraceSource.NewArgumentNullException("instanceName"); + throw PSTraceSource.NewArgumentNullException(nameof(instanceName)); } this.Body = body; @@ -6842,7 +6842,7 @@ public DynamicKeywordStatementAst(IScriptExtent extent, { if (commandElements == null || commandElements.Count() <= 0) { - throw PSTraceSource.NewArgumentException("commandElements"); + throw PSTraceSource.NewArgumentException(nameof(commandElements)); } this.CommandElements = new ReadOnlyCollection(commandElements.ToArray()); @@ -7348,7 +7348,7 @@ public BinaryExpressionAst(IScriptExtent extent, ExpressionAst left, TokenKind @ { if ((@operator.GetTraits() & TokenFlags.BinaryOperator) == 0) { - throw PSTraceSource.NewArgumentException("operator"); + throw PSTraceSource.NewArgumentException(nameof(@operator)); } if (left == null || right == null || errorPosition == null) @@ -7461,12 +7461,12 @@ public UnaryExpressionAst(IScriptExtent extent, TokenKind tokenKind, ExpressionA { if ((tokenKind.GetTraits() & TokenFlags.UnaryOperator) == 0) { - throw PSTraceSource.NewArgumentException("tokenKind"); + throw PSTraceSource.NewArgumentException(nameof(tokenKind)); } if (child == null) { - throw PSTraceSource.NewArgumentNullException("child"); + throw PSTraceSource.NewArgumentNullException(nameof(child)); } this.TokenKind = tokenKind; @@ -7548,7 +7548,7 @@ public BlockStatementAst(IScriptExtent extent, Token kind, StatementBlockAst bod if (kind.Kind != TokenKind.Sequence && kind.Kind != TokenKind.Parallel) { - throw PSTraceSource.NewArgumentException("kind"); + throw PSTraceSource.NewArgumentException(nameof(kind)); } this.Kind = kind; @@ -8179,7 +8179,7 @@ public TypeName(IScriptExtent extent, string name) var c = name[0]; if (c == '[' || c == ']' || c == ',') { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(name)); } int backtick = name.IndexOf('`'); @@ -8209,7 +8209,7 @@ public TypeName(IScriptExtent extent, string name, string assembly) { if (string.IsNullOrEmpty(assembly)) { - throw PSTraceSource.NewArgumentNullException("assembly"); + throw PSTraceSource.NewArgumentNullException(nameof(assembly)); } AssemblyName = assembly; @@ -8449,7 +8449,7 @@ public GenericTypeName(IScriptExtent extent, ITypeName genericTypeName, IEnumera if (genericArguments == null) { - throw PSTraceSource.NewArgumentException("genericArguments"); + throw PSTraceSource.NewArgumentException(nameof(genericArguments)); } Extent = extent; @@ -8458,7 +8458,7 @@ public GenericTypeName(IScriptExtent extent, ITypeName genericTypeName, IEnumera if (this.GenericArguments.Count == 0) { - throw PSTraceSource.NewArgumentException("genericArguments"); + throw PSTraceSource.NewArgumentException(nameof(genericArguments)); } } @@ -8746,7 +8746,7 @@ public ArrayTypeName(IScriptExtent extent, ITypeName elementType, int rank) if (rank <= 0) { - throw PSTraceSource.NewArgumentException("rank"); + throw PSTraceSource.NewArgumentException(nameof(rank)); } Extent = extent; @@ -8941,7 +8941,7 @@ public ReflectionTypeName(Type type) { if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } _type = type; @@ -9042,7 +9042,7 @@ public TypeExpressionAst(IScriptExtent extent, ITypeName typeName) { if (typeName == null) { - throw PSTraceSource.NewArgumentNullException("typeName"); + throw PSTraceSource.NewArgumentNullException(nameof(typeName)); } this.TypeName = typeName; @@ -9107,7 +9107,7 @@ public VariableExpressionAst(IScriptExtent extent, string variableName, bool spl { if (string.IsNullOrEmpty(variableName)) { - throw PSTraceSource.NewArgumentNullException("variableName"); + throw PSTraceSource.NewArgumentNullException(nameof(variableName)); } this.VariablePath = new VariablePath(variableName); @@ -9134,7 +9134,7 @@ public VariableExpressionAst(IScriptExtent extent, VariablePath variablePath, bo { if (variablePath == null) { - throw PSTraceSource.NewArgumentNullException("variablePath"); + throw PSTraceSource.NewArgumentNullException(nameof(variablePath)); } this.VariablePath = variablePath; @@ -9429,7 +9429,7 @@ public StringConstantExpressionAst(IScriptExtent extent, string value, StringCon { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } this.StringConstantType = stringConstantType; @@ -9529,13 +9529,13 @@ public ExpandableStringExpressionAst(IScriptExtent extent, { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } if (type != StringConstantType.DoubleQuoted && type != StringConstantType.DoubleQuotedHereString && type != StringConstantType.BareWord) { - throw PSTraceSource.NewArgumentException("type"); + throw PSTraceSource.NewArgumentException(nameof(type)); } var ast = Language.Parser.ScanString(value); @@ -9676,7 +9676,7 @@ public ScriptBlockExpressionAst(IScriptExtent extent, ScriptBlockAst scriptBlock { if (scriptBlock == null) { - throw PSTraceSource.NewArgumentNullException("scriptBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock)); } this.ScriptBlock = scriptBlock; @@ -9748,7 +9748,7 @@ public ArrayLiteralAst(IScriptExtent extent, IList elements) { if (elements == null || !elements.Any()) { - throw PSTraceSource.NewArgumentException("elements"); + throw PSTraceSource.NewArgumentException(nameof(elements)); } this.Elements = new ReadOnlyCollection(elements); @@ -9921,7 +9921,7 @@ public ArrayExpressionAst(IScriptExtent extent, StatementBlockAst statementBlock { if (statementBlock == null) { - throw PSTraceSource.NewArgumentNullException("statementBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(statementBlock)); } this.SubExpression = statementBlock; @@ -9987,7 +9987,7 @@ public ParenExpressionAst(IScriptExtent extent, PipelineBaseAst pipeline) { if (pipeline == null) { - throw PSTraceSource.NewArgumentNullException("pipeline"); + throw PSTraceSource.NewArgumentNullException(nameof(pipeline)); } this.Pipeline = pipeline; @@ -10053,7 +10053,7 @@ public SubExpressionAst(IScriptExtent extent, StatementBlockAst statementBlock) { if (statementBlock == null) { - throw PSTraceSource.NewArgumentNullException("statementBlock"); + throw PSTraceSource.NewArgumentNullException(nameof(statementBlock)); } this.SubExpression = statementBlock; @@ -10113,7 +10113,7 @@ public UsingExpressionAst(IScriptExtent extent, ExpressionAst expressionAst) { if (expressionAst == null) { - throw PSTraceSource.NewArgumentNullException("expressionAst"); + throw PSTraceSource.NewArgumentNullException(nameof(expressionAst)); } RuntimeUsingIndex = -1; @@ -10163,7 +10163,7 @@ public static VariableExpressionAst ExtractUsingVariable(UsingExpressionAst usin { if (usingExpressionAst == null) { - throw new ArgumentNullException("usingExpressionAst"); + throw new ArgumentNullException(nameof(usingExpressionAst)); } return ExtractUsingVariableImpl(usingExpressionAst); diff --git a/src/System.Management.Automation/engine/parser/tokenizer.cs b/src/System.Management.Automation/engine/parser/tokenizer.cs index 64cd02d4185..ba8fdeac87d 100644 --- a/src/System.Management.Automation/engine/parser/tokenizer.cs +++ b/src/System.Management.Automation/engine/parser/tokenizer.cs @@ -153,7 +153,7 @@ public static bool ContainsKeyword(string name) { if (string.IsNullOrEmpty(name)) { - PSArgumentNullException e = PSTraceSource.NewArgumentNullException("name"); + PSArgumentNullException e = PSTraceSource.NewArgumentNullException(nameof(name)); throw e; } @@ -167,7 +167,7 @@ public static void AddKeyword(DynamicKeyword keywordToAdd) { if (keywordToAdd == null) { - PSArgumentNullException e = PSTraceSource.NewArgumentNullException("keywordToAdd"); + PSArgumentNullException e = PSTraceSource.NewArgumentNullException(nameof(keywordToAdd)); throw e; } @@ -191,7 +191,7 @@ public static void RemoveKeyword(string name) { if (string.IsNullOrEmpty(name)) { - PSArgumentNullException e = PSTraceSource.NewArgumentNullException("name"); + PSArgumentNullException e = PSTraceSource.NewArgumentNullException(nameof(name)); throw e; } @@ -207,7 +207,7 @@ internal static bool IsHiddenKeyword(string name) { if (string.IsNullOrEmpty(name)) { - PSArgumentNullException e = PSTraceSource.NewArgumentNullException("name"); + PSArgumentNullException e = PSTraceSource.NewArgumentNullException(nameof(name)); throw e; } diff --git a/src/System.Management.Automation/engine/pipeline.cs b/src/System.Management.Automation/engine/pipeline.cs index d963afffad1..e118bce374d 100644 --- a/src/System.Management.Automation/engine/pipeline.cs +++ b/src/System.Management.Automation/engine/pipeline.cs @@ -285,7 +285,7 @@ internal int Add(CommandProcessorBase commandProcessor) internal void AddRedirectionPipe(PipelineProcessor pipelineProcessor) { - if (pipelineProcessor == null) throw PSTraceSource.NewArgumentNullException("pipelineProcessor"); + if (pipelineProcessor == null) throw PSTraceSource.NewArgumentNullException(nameof(pipelineProcessor)); if (_redirectionPipes == null) _redirectionPipes = new List(); _redirectionPipes.Add(pipelineProcessor); @@ -317,7 +317,7 @@ internal int AddCommand(CommandProcessorBase commandProcessor, int readFromComma { if (commandProcessor == null) { - throw PSTraceSource.NewArgumentNullException("commandProcessor"); + throw PSTraceSource.NewArgumentNullException(nameof(commandProcessor)); } if (_commands == null) @@ -349,7 +349,7 @@ internal int AddCommand(CommandProcessorBase commandProcessor, int readFromComma { // "First command cannot have input" throw PSTraceSource.NewArgumentException( - "readFromCommand", + nameof(readFromCommand), PipelineStrings.FirstCommandCannotHaveInput); } @@ -360,7 +360,7 @@ internal int AddCommand(CommandProcessorBase commandProcessor, int readFromComma { // "invalid command number" throw PSTraceSource.NewArgumentException( - "readFromCommand", + nameof(readFromCommand), PipelineStrings.InvalidCommandNumber); } else diff --git a/src/System.Management.Automation/engine/regex.cs b/src/System.Management.Automation/engine/regex.cs index 2a62a8a543e..d04c3a98fba 100644 --- a/src/System.Management.Automation/engine/regex.cs +++ b/src/System.Management.Automation/engine/regex.cs @@ -125,7 +125,7 @@ public WildcardPattern(string pattern, WildcardOptions options) public static WildcardPattern Get(string pattern, WildcardOptions options) { if (pattern == null) - throw PSTraceSource.NewArgumentNullException("pattern"); + throw PSTraceSource.NewArgumentNullException(nameof(pattern)); if (pattern.Length == 1 && pattern[0] == '*') return s_matchAllIgnoreCasePattern; @@ -449,7 +449,7 @@ internal WildcardPatternException(ErrorRecord errorRecord) { if (errorRecord == null) { - throw new ArgumentNullException("errorRecord"); + throw new ArgumentNullException(nameof(errorRecord)); } _errorRecord = errorRecord; diff --git a/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs b/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs index ccee756d654..ba4e08c8f6f 100644 --- a/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs +++ b/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs @@ -238,7 +238,7 @@ internal void ExecuteVoid(Action writeErrorAction) // Create an error record and write it to the stream. ErrorRecord errorRecord = new ErrorRecord( exception, - PSRemotingErrorId.RemoteHostCallFailed.ToString(), + nameof(PSRemotingErrorId.RemoteHostCallFailed), ErrorCategory.InvalidArgument, _remoteHostCall.MethodName); writeErrorAction(errorRecord); diff --git a/src/System.Management.Automation/engine/remoting/client/Job.cs b/src/System.Management.Automation/engine/remoting/client/Job.cs index 7cbf139d361..1c8daf5630e 100644 --- a/src/System.Management.Automation/engine/remoting/client/Job.cs +++ b/src/System.Management.Automation/engine/remoting/client/Job.cs @@ -333,7 +333,7 @@ public JobStateEventArgs(JobStateInfo jobStateInfo, JobStateInfo previousJobStat { if (jobStateInfo == null) { - throw PSTraceSource.NewArgumentNullException("jobStateInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(jobStateInfo)); } JobStateInfo = jobStateInfo; @@ -366,7 +366,7 @@ public sealed class JobIdentifier internal JobIdentifier(int id, Guid instanceId) { if (id <= 0) - PSTraceSource.NewArgumentException("id", RemotingErrorIdStrings.JobSessionIdLessThanOne, id); + PSTraceSource.NewArgumentException(nameof(id), RemotingErrorIdStrings.JobSessionIdLessThanOne, id); Id = id; InstanceId = instanceId; } @@ -463,10 +463,10 @@ protected Job(string command, string name, IList childJobs) protected Job(string command, string name, JobIdentifier token) { if (token == null) - throw PSTraceSource.NewArgumentNullException("token", RemotingErrorIdStrings.JobIdentifierNull); + throw PSTraceSource.NewArgumentNullException(nameof(token), RemotingErrorIdStrings.JobIdentifierNull); if (token.Id > s_jobIdSeed) { - throw PSTraceSource.NewArgumentException("token", RemotingErrorIdStrings.JobIdNotYetAssigned, token.Id); + throw PSTraceSource.NewArgumentException(nameof(token), RemotingErrorIdStrings.JobIdNotYetAssigned, token.Id); } Command = command; @@ -3882,12 +3882,12 @@ public RemotingJobDebugger( { if (debugger == null) { - throw new PSArgumentNullException("debugger"); + throw new PSArgumentNullException(nameof(debugger)); } if (runspace == null) { - throw new PSArgumentNullException("runspace"); + throw new PSArgumentNullException(nameof(runspace)); } _wrappedDebugger = debugger; diff --git a/src/System.Management.Automation/engine/remoting/client/Job2.cs b/src/System.Management.Automation/engine/remoting/client/Job2.cs index b97243651fb..7b972cf5a1a 100644 --- a/src/System.Management.Automation/engine/remoting/client/Job2.cs +++ b/src/System.Management.Automation/engine/remoting/client/Job2.cs @@ -704,7 +704,7 @@ public void AddChildJob(Job2 childJob) AssertNotDisposed(); if (childJob == null) { - throw new ArgumentNullException("childJob"); + throw new ArgumentNullException(nameof(childJob)); } _tracer.WriteMessage(TraceClassName, "AddChildJob", Guid.Empty, childJob, "Adding Child to Parent with InstanceId : ", InstanceId.ToString()); @@ -2181,7 +2181,7 @@ protected JobFailedException(SerializationInfo serializationInfo, StreamingConte public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/engine/remoting/client/JobManager.cs b/src/System.Management.Automation/engine/remoting/client/JobManager.cs index 88952ef893b..6ef47c19752 100644 --- a/src/System.Management.Automation/engine/remoting/client/JobManager.cs +++ b/src/System.Management.Automation/engine/remoting/client/JobManager.cs @@ -178,7 +178,7 @@ public Job2 NewJob(JobDefinition definition) { if (definition == null) { - throw new ArgumentNullException("definition"); + throw new ArgumentNullException(nameof(definition)); } JobSourceAdapter sourceAdapter = GetJobSourceAdapter(definition); @@ -218,12 +218,12 @@ public Job2 NewJob(JobInvocationInfo specification) { if (specification == null) { - throw new ArgumentNullException("specification"); + throw new ArgumentNullException(nameof(specification)); } if (specification.Definition == null) { - throw new ArgumentException(RemotingErrorIdStrings.NewJobSpecificationError, "specification"); + throw new ArgumentException(RemotingErrorIdStrings.NewJobSpecificationError, nameof(specification)); } JobSourceAdapter sourceAdapter = GetJobSourceAdapter(specification.Definition); @@ -263,12 +263,12 @@ public void PersistJob(Job2 job, JobDefinition definition) { if (job == null) { - throw new PSArgumentNullException("job"); + throw new PSArgumentNullException(nameof(job)); } if (definition == null) { - throw new PSArgumentNullException("definition"); + throw new PSArgumentNullException(nameof(definition)); } JobSourceAdapter sourceAdapter = GetJobSourceAdapter(definition); diff --git a/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs b/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs index 8802c3a2f61..f38ac4a39d0 100644 --- a/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs +++ b/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs @@ -405,7 +405,7 @@ public void StoreJobIdForReuse(Job2 job, bool recurse) { if (job == null) { - PSTraceSource.NewArgumentNullException("job", RemotingErrorIdStrings.JobSourceAdapterCannotSaveNullJob); + PSTraceSource.NewArgumentNullException(nameof(job), RemotingErrorIdStrings.JobSourceAdapterCannotSaveNullJob); } JobManager.SaveJobId(job.InstanceId, job.Id, this.GetType().Name); diff --git a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs index 640bbb11f33..8c35c5f948f 100644 --- a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs +++ b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs @@ -1074,7 +1074,7 @@ public override void EndDisconnect(IAsyncResult asyncResult) { if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } RunspacePoolAsyncResult rsAsyncResult = asyncResult as RunspacePoolAsyncResult; @@ -1083,7 +1083,7 @@ public override void EndDisconnect(IAsyncResult asyncResult) (rsAsyncResult.OwnerId != instanceId) || (rsAsyncResult.IsAssociatedWithAsyncOpen)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), RunspacePoolStrings.AsyncResultNotOwned, "IAsyncResult", "BeginOpen"); @@ -1184,7 +1184,7 @@ public override void EndConnect(IAsyncResult asyncResult) { if (asyncResult == null) { - throw PSTraceSource.NewArgumentNullException("asyncResult"); + throw PSTraceSource.NewArgumentNullException(nameof(asyncResult)); } RunspacePoolAsyncResult rsAsyncResult = asyncResult as RunspacePoolAsyncResult; @@ -1193,7 +1193,7 @@ public override void EndConnect(IAsyncResult asyncResult) (rsAsyncResult.OwnerId != instanceId) || (rsAsyncResult.IsAssociatedWithAsyncOpen)) { - throw PSTraceSource.NewArgumentException("asyncResult", + throw PSTraceSource.NewArgumentException(nameof(asyncResult), RunspacePoolStrings.AsyncResultNotOwned, "IAsyncResult", "BeginOpen"); diff --git a/src/System.Management.Automation/engine/remoting/client/RemotingErrorRecord.cs b/src/System.Management.Automation/engine/remoting/client/RemotingErrorRecord.cs index 5665a0e3be0..7a7a70f9296 100644 --- a/src/System.Management.Automation/engine/remoting/client/RemotingErrorRecord.cs +++ b/src/System.Management.Automation/engine/remoting/client/RemotingErrorRecord.cs @@ -63,7 +63,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -143,7 +143,7 @@ public RemotingProgressRecord(ProgressRecord progressRecord, OriginInfo originIn private static ProgressRecord Validate(ProgressRecord progressRecord) { - if (progressRecord == null) throw new ArgumentNullException("progressRecord"); + if (progressRecord == null) throw new ArgumentNullException(nameof(progressRecord)); return progressRecord; } } diff --git a/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs b/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs index f63376179a8..a6ad69843cc 100644 --- a/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs +++ b/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs @@ -296,7 +296,7 @@ internal void AddChildJobAndPotentiallyBlock( { using (var jobGotEnqueued = new ManualResetEventSlim(initialState: false)) { - if (childJob == null) throw new ArgumentNullException("childJob"); + if (childJob == null) throw new ArgumentNullException(nameof(childJob)); this.AddChildJobWithoutBlocking(childJob, flags, jobGotEnqueued.Set); jobGotEnqueued.Wait(); @@ -310,7 +310,7 @@ internal void AddChildJobAndPotentiallyBlock( { using (var forwardingCancellation = new CancellationTokenSource()) { - if (childJob == null) throw new ArgumentNullException("childJob"); + if (childJob == null) throw new ArgumentNullException(nameof(childJob)); this.AddChildJobWithoutBlocking(childJob, flags, forwardingCancellation.Cancel); this.ForwardAllResultsToCmdlet(cmdlet, forwardingCancellation.Token); @@ -371,8 +371,8 @@ internal void DisableFlowControlForPendingCmdletActionsQueue() /// internal void AddChildJobWithoutBlocking(StartableJob childJob, ChildJobFlags flags, Action jobEnqueuedAction = null) { - if (childJob == null) throw new ArgumentNullException("childJob"); - if (childJob.JobStateInfo.State != JobState.NotStarted) throw new ArgumentException(RemotingErrorIdStrings.ThrottlingJobChildAlreadyRunning, "childJob"); + if (childJob == null) throw new ArgumentNullException(nameof(childJob)); + if (childJob.JobStateInfo.State != JobState.NotStarted) throw new ArgumentException(RemotingErrorIdStrings.ThrottlingJobChildAlreadyRunning, nameof(childJob)); this.AssertNotDisposed(); JobStateInfo newJobStateInfo = null; diff --git a/src/System.Management.Automation/engine/remoting/client/clientremotesession.cs b/src/System.Management.Automation/engine/remoting/client/clientremotesession.cs index fc7e4ffa8c9..e3249765446 100644 --- a/src/System.Management.Automation/engine/remoting/client/clientremotesession.cs +++ b/src/System.Management.Automation/engine/remoting/client/clientremotesession.cs @@ -299,7 +299,7 @@ private void HandleConnectionStateChanged(object sender, RemoteSessionStateEvent { if (arg == null) { - throw PSTraceSource.NewArgumentNullException("arg"); + throw PSTraceSource.NewArgumentNullException(nameof(arg)); } if (arg.SessionStateInfo.State == RemoteSessionState.EstablishedAndKeyReceived) // TODO - Client session would never get into this state... to be removed @@ -454,12 +454,12 @@ private void HandleNegotiationReceived(object sender, RemoteSessionNegotiationEv { if (arg == null) { - throw PSTraceSource.NewArgumentNullException("arg"); + throw PSTraceSource.NewArgumentNullException(nameof(arg)); } if (arg.RemoteSessionCapability == null) { - throw PSTraceSource.NewArgumentException("arg"); + throw PSTraceSource.NewArgumentException(nameof(arg)); } Context.ServerCapability = arg.RemoteSessionCapability; diff --git a/src/System.Management.Automation/engine/remoting/client/clientremotesessionprotocolstatemachine.cs b/src/System.Management.Automation/engine/remoting/client/clientremotesessionprotocolstatemachine.cs index 63713c2c200..ec55f22fc22 100644 --- a/src/System.Management.Automation/engine/remoting/client/clientremotesessionprotocolstatemachine.cs +++ b/src/System.Management.Automation/engine/remoting/client/clientremotesessionprotocolstatemachine.cs @@ -190,7 +190,7 @@ private void SetStateHandler(object sender, RemoteSessionStateMachineEventArgs e "State can be set to NegotiationReceived only when RemoteSessionCapability is not null"); if (eventArgs.RemoteSessionCapability == null) { - throw PSTraceSource.NewArgumentException("eventArgs"); + throw PSTraceSource.NewArgumentException(nameof(eventArgs)); } SetState(RemoteSessionState.NegotiationReceived, null); @@ -554,7 +554,7 @@ private void RaiseEventPrivate(RemoteSessionStateMachineEventArgs arg) { if (arg == null) { - throw PSTraceSource.NewArgumentNullException("arg"); + throw PSTraceSource.NewArgumentNullException(nameof(arg)); } EventHandler handler = _stateMachineHandle[(int)State, (int)arg.StateEvent]; diff --git a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs index 5b7ddd301ee..a711c7dd8f2 100644 --- a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs +++ b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs @@ -173,7 +173,7 @@ private RemotePipeline(RemotePipeline pipeline) : // originally copied it from PipelineBase if (pipeline == null) { - throw PSTraceSource.NewArgumentNullException("pipeline"); + throw PSTraceSource.NewArgumentNullException(nameof(pipeline)); } if (pipeline._disposed) diff --git a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs index 0b8cd69e2de..61be515408f 100644 --- a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs +++ b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs @@ -1041,7 +1041,7 @@ public override Pipeline CreatePipeline(string command) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } return CoreCreatePipeline(command, false, false); @@ -1062,7 +1062,7 @@ public override Pipeline CreatePipeline(string command, bool addToHistory) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } return CoreCreatePipeline(command, addToHistory, false); @@ -1097,7 +1097,7 @@ public override Pipeline CreateNestedPipeline(string command, bool addToHistory) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } return CoreCreatePipeline(command, addToHistory, true); @@ -1853,7 +1853,7 @@ public RemoteDebugger(RemoteRunspace runspace) { if (runspace == null) { - throw new PSArgumentNullException("runspace"); + throw new PSArgumentNullException(nameof(runspace)); } _runspace = runspace; @@ -1882,12 +1882,12 @@ public override DebuggerCommandResults ProcessCommand(PSCommand command, PSDataC if (command == null) { - throw new PSArgumentNullException("command"); + throw new PSArgumentNullException(nameof(command)); } if (output == null) { - throw new PSArgumentNullException("output"); + throw new PSArgumentNullException(nameof(output)); } if (!DebuggerStopped) @@ -2978,7 +2978,7 @@ public override void SetVariable(string name, object value) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } // Verify the runspace has the Set-Variable command. For performance, throw if we got an error @@ -3038,7 +3038,7 @@ public override object GetVariable(string name) { if (name == null) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } // Verify the runspace has the Get-Variable command. For performance, throw if we got an error diff --git a/src/System.Management.Automation/engine/remoting/client/remotingprotocolimplementation.cs b/src/System.Management.Automation/engine/remoting/client/remotingprotocolimplementation.cs index 486b9c4cf13..42c50b42035 100644 --- a/src/System.Management.Automation/engine/remoting/client/remotingprotocolimplementation.cs +++ b/src/System.Management.Automation/engine/remoting/client/remotingprotocolimplementation.cs @@ -66,7 +66,7 @@ internal ClientRemoteSessionDSHandlerImpl(ClientRemoteSession session, if (session == null) { - throw PSTraceSource.NewArgumentNullException("session"); + throw PSTraceSource.NewArgumentNullException(nameof(session)); } _session = session; @@ -278,7 +278,7 @@ private void HandleStateChanged(object sender, RemoteSessionStateEventArgs arg) { if (arg == null) { - throw PSTraceSource.NewArgumentNullException("arg"); + throw PSTraceSource.NewArgumentNullException(nameof(arg)); } // Enqueue session related negotiation packets first @@ -540,14 +540,14 @@ internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataArg) { if (dataArg == null) { - throw PSTraceSource.NewArgumentNullException("dataArg"); + throw PSTraceSource.NewArgumentNullException(nameof(dataArg)); } RemoteDataObject rcvdData = dataArg.ReceivedData; if (rcvdData == null) { - throw PSTraceSource.NewArgumentException("dataArg"); + throw PSTraceSource.NewArgumentException(nameof(dataArg)); } RemotingDestination destination = rcvdData.Destination; @@ -610,7 +610,7 @@ private void ProcessSessionMessages(RemoteDataEventArgs arg) { if (arg == null || arg.ReceivedData == null) { - throw PSTraceSource.NewArgumentNullException("arg"); + throw PSTraceSource.NewArgumentNullException(nameof(arg)); } RemoteDataObject rcvdData = arg.ReceivedData; @@ -684,7 +684,7 @@ internal void ProcessNonSessionMessages(RemoteDataObject rcvdData) // TODO: Consider changing to Dbg.Assert() if (rcvdData == null) { - throw PSTraceSource.NewArgumentNullException("rcvdData"); + throw PSTraceSource.NewArgumentNullException(nameof(rcvdData)); } RemotingTargetInterface targetInterface = rcvdData.TargetInterface; diff --git a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs index 6b2fa8c804e..86734f85fc4 100644 --- a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs @@ -2137,7 +2137,7 @@ public void StartProgress( if (string.IsNullOrEmpty(computerName)) { - throw new ArgumentNullException("computerName"); + throw new ArgumentNullException(nameof(computerName)); } lock (_syncObject) diff --git a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs index a000e2d0bbe..248c3a5718e 100644 --- a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs +++ b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs @@ -986,7 +986,7 @@ protected void ValidateRemoteRunspacesSpecified() { ThrowTerminatingError(new ErrorRecord(new ArgumentException( GetMessage(RemotingErrorIdStrings.RemoteRunspaceInfoHasDuplicates)), - PSRemotingErrorId.RemoteRunspaceInfoHasDuplicates.ToString(), + nameof(PSRemotingErrorId.RemoteRunspaceInfoHasDuplicates), ErrorCategory.InvalidArgument, Session)); } @@ -997,7 +997,7 @@ protected void ValidateRemoteRunspacesSpecified() { ThrowTerminatingError(new ErrorRecord(new ArgumentException( GetMessage(RemotingErrorIdStrings.RemoteRunspaceInfoLimitExceeded)), - PSRemotingErrorId.RemoteRunspaceInfoLimitExceeded.ToString(), + nameof(PSRemotingErrorId.RemoteRunspaceInfoLimitExceeded), ErrorCategory.InvalidArgument, Session)); } } @@ -1608,7 +1608,7 @@ protected virtual void CreateHelpersForSpecifiedVMSession() ThrowTerminatingError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.HyperVModuleNotAvailable), - PSRemotingErrorId.HyperVModuleNotAvailable.ToString(), + nameof(PSRemotingErrorId.HyperVModuleNotAvailable), ErrorCategory.NotInstalled, null)); @@ -1656,7 +1656,7 @@ protected virtual void CreateHelpersForSpecifiedVMSession() ThrowTerminatingError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.HyperVModuleNotAvailable), - PSRemotingErrorId.HyperVModuleNotAvailable.ToString(), + nameof(PSRemotingErrorId.HyperVModuleNotAvailable), ErrorCategory.NotInstalled, null)); @@ -1692,7 +1692,7 @@ protected virtual void CreateHelpersForSpecifiedVMSession() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMNameNotSingle, this.VMName[index])), - PSRemotingErrorId.InvalidVMNameNotSingle.ToString(), + nameof(PSRemotingErrorId.InvalidVMNameNotSingle), ErrorCategory.InvalidArgument, null)); @@ -1706,7 +1706,7 @@ protected virtual void CreateHelpersForSpecifiedVMSession() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMIdNotSingle, this.VMId[index].ToString(null))), - PSRemotingErrorId.InvalidVMIdNotSingle.ToString(), + nameof(PSRemotingErrorId.InvalidVMIdNotSingle), ErrorCategory.InvalidArgument, null)); @@ -1718,7 +1718,7 @@ protected virtual void CreateHelpersForSpecifiedVMSession() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMState, this.VMName[index])), - PSRemotingErrorId.InvalidVMState.ToString(), + nameof(PSRemotingErrorId.InvalidVMState), ErrorCategory.InvalidArgument, null)); @@ -2013,12 +2013,12 @@ protected ScriptBlock GetScriptBlockFromFile(string filePath, bool isLiteralPath // Make sure filepath doesn't contain wildcards if ((!isLiteralPath) && WildcardPattern.ContainsWildcardCharacters(filePath)) { - throw new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.WildCardErrorFilePathParameter), "filePath"); + throw new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.WildCardErrorFilePathParameter), nameof(filePath)); } if (!filePath.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase)) { - throw new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.FilePathShouldPS1Extension), "filePath"); + throw new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.FilePathShouldPS1Extension), nameof(filePath)); } // Resolve file path @@ -2430,7 +2430,7 @@ private List GetUsingVariables(ScriptBlock localScriptBlo { if (localScriptBlock == null) { - throw new ArgumentNullException("localScriptBlock", "Caller needs to make sure the parameter value is not null"); + throw new ArgumentNullException(nameof(localScriptBlock), "Caller needs to make sure the parameter value is not null"); } var allUsingExprs = UsingExpressionAstSearcher.FindAllUsingExpressionExceptForWorkflow(localScriptBlock.Ast); @@ -4368,9 +4368,9 @@ public AuthenticationMechanism ProxyAuthentication default: string message = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.ProxyAmbiguousAuthentication, value, - AuthenticationMechanism.Basic.ToString(), - AuthenticationMechanism.Negotiate.ToString(), - AuthenticationMechanism.Digest.ToString()); + nameof(AuthenticationMechanism.Basic), + nameof(AuthenticationMechanism.Negotiate), + nameof(AuthenticationMechanism.Digest)); throw new ArgumentException(message); } } diff --git a/src/System.Management.Automation/engine/remoting/commands/PopRunspaceCommand.cs b/src/System.Management.Automation/engine/remoting/commands/PopRunspaceCommand.cs index c5d9648cd0a..5f80dfb5d0c 100644 --- a/src/System.Management.Automation/engine/remoting/commands/PopRunspaceCommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/PopRunspaceCommand.cs @@ -28,7 +28,7 @@ protected override void ProcessRecord() WriteError( new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.HostDoesNotSupportPushRunspace)), - PSRemotingErrorId.HostDoesNotSupportPushRunspace.ToString(), + nameof(PSRemotingErrorId.HostDoesNotSupportPushRunspace), ErrorCategory.InvalidArgument, null)); return; diff --git a/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs b/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs index 9a063d935e1..a7751e0138d 100644 --- a/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs @@ -240,7 +240,7 @@ protected override void ProcessRecord() WriteError( new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.HostDoesNotSupportPushRunspace)), - PSRemotingErrorId.HostDoesNotSupportPushRunspace.ToString(), + nameof(PSRemotingErrorId.HostDoesNotSupportPushRunspace), ErrorCategory.InvalidArgument, null)); return; @@ -373,7 +373,7 @@ protected override void ProcessRecord() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.EnterPSSessionBrokenSession, sessionName, remoteRunspace.ConnectionInfo.ComputerName, remoteRunspace.InstanceId)), - PSRemotingErrorId.PushedRunspaceMustBeOpen.ToString(), + nameof(PSRemotingErrorId.PushedRunspaceMustBeOpen), ErrorCategory.InvalidArgument, null)); } @@ -382,7 +382,7 @@ protected override void ProcessRecord() WriteError( new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.PushedRunspaceMustBeOpen)), - PSRemotingErrorId.PushedRunspaceMustBeOpen.ToString(), + nameof(PSRemotingErrorId.PushedRunspaceMustBeOpen), ErrorCategory.InvalidArgument, null)); } @@ -537,7 +537,7 @@ protected override void StopProcessing() WriteError( new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.HostDoesNotSupportPushRunspace)), - PSRemotingErrorId.HostDoesNotSupportPushRunspace.ToString(), + nameof(PSRemotingErrorId.HostDoesNotSupportPushRunspace), ErrorCategory.InvalidArgument, null)); return; @@ -940,7 +940,7 @@ private RemoteRunspace GetRunspaceForVMSession() WriteError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.HyperVModuleNotAvailable), - PSRemotingErrorId.HyperVModuleNotAvailable.ToString(), + nameof(PSRemotingErrorId.HyperVModuleNotAvailable), ErrorCategory.NotInstalled, null)); @@ -952,7 +952,7 @@ private RemoteRunspace GetRunspaceForVMSession() WriteError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.InvalidVMId), - PSRemotingErrorId.InvalidVMId.ToString(), + nameof(PSRemotingErrorId.InvalidVMId), ErrorCategory.InvalidArgument, null)); @@ -977,7 +977,7 @@ private RemoteRunspace GetRunspaceForVMSession() WriteError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.HyperVModuleNotAvailable), - PSRemotingErrorId.HyperVModuleNotAvailable.ToString(), + nameof(PSRemotingErrorId.HyperVModuleNotAvailable), ErrorCategory.NotInstalled, null)); @@ -989,7 +989,7 @@ private RemoteRunspace GetRunspaceForVMSession() WriteError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.InvalidVMNameNoVM), - PSRemotingErrorId.InvalidVMNameNoVM.ToString(), + nameof(PSRemotingErrorId.InvalidVMNameNoVM), ErrorCategory.InvalidArgument, null)); @@ -1000,7 +1000,7 @@ private RemoteRunspace GetRunspaceForVMSession() WriteError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.InvalidVMNameMultipleVM), - PSRemotingErrorId.InvalidVMNameMultipleVM.ToString(), + nameof(PSRemotingErrorId.InvalidVMNameMultipleVM), ErrorCategory.InvalidArgument, null)); @@ -1020,7 +1020,7 @@ private RemoteRunspace GetRunspaceForVMSession() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMState, this.VMName)), - PSRemotingErrorId.InvalidVMState.ToString(), + nameof(PSRemotingErrorId.InvalidVMState), ErrorCategory.InvalidArgument, null)); diff --git a/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs b/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs index c9df93cd05b..16f4af800f7 100644 --- a/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs @@ -416,12 +416,12 @@ private void HandleRunspaceStateChanged(object sender, OperationStateEventArgs s { if (sender == null) { - throw PSTraceSource.NewArgumentNullException("sender"); + throw PSTraceSource.NewArgumentNullException(nameof(sender)); } if (stateEventArgs == null) { - throw PSTraceSource.NewArgumentNullException("stateEventArgs"); + throw PSTraceSource.NewArgumentNullException(nameof(stateEventArgs)); } RunspaceStateEventArgs runspaceStateEventArgs = @@ -909,7 +909,7 @@ private List CreateRunspacesWhenVMParameterSpecified() ThrowTerminatingError( new ErrorRecord( new ArgumentException(RemotingErrorIdStrings.HyperVModuleNotAvailable), - PSRemotingErrorId.HyperVModuleNotAvailable.ToString(), + nameof(PSRemotingErrorId.HyperVModuleNotAvailable), ErrorCategory.NotInstalled, null)); @@ -927,7 +927,7 @@ private List CreateRunspacesWhenVMParameterSpecified() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMIdNotSingle, this.VMId[index].ToString(null))), - PSRemotingErrorId.InvalidVMIdNotSingle.ToString(), + nameof(PSRemotingErrorId.InvalidVMIdNotSingle), ErrorCategory.InvalidArgument, null)); @@ -941,7 +941,7 @@ private List CreateRunspacesWhenVMParameterSpecified() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMNameNotSingle, this.VMName[index])), - PSRemotingErrorId.InvalidVMNameNotSingle.ToString(), + nameof(PSRemotingErrorId.InvalidVMNameNotSingle), ErrorCategory.InvalidArgument, null)); @@ -962,7 +962,7 @@ private List CreateRunspacesWhenVMParameterSpecified() new ErrorRecord( new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMState, this.VMName[index])), - PSRemotingErrorId.InvalidVMState.ToString(), + nameof(PSRemotingErrorId.InvalidVMState), ErrorCategory.InvalidArgument, null)); diff --git a/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs b/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs index 1ccdd82c396..ad233ccb481 100644 --- a/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs +++ b/src/System.Management.Automation/engine/remoting/commands/remotingcommandutil.cs @@ -36,12 +36,12 @@ internal static bool HasRepeatingRunspaces(PSSession[] runspaceInfos) { if (runspaceInfos == null) { - throw PSTraceSource.NewArgumentNullException("runspaceInfos"); + throw PSTraceSource.NewArgumentNullException(nameof(runspaceInfos)); } if (runspaceInfos.GetLength(0) == 0) { - throw PSTraceSource.NewArgumentException("runspaceInfos"); + throw PSTraceSource.NewArgumentException(nameof(runspaceInfos)); } for (int i = 0; i < runspaceInfos.GetLength(0); i++) @@ -65,12 +65,12 @@ internal static bool ExceedMaximumAllowableRunspaces(PSSession[] runspaceInfos) { if (runspaceInfos == null) { - throw PSTraceSource.NewArgumentNullException("runspaceInfos"); + throw PSTraceSource.NewArgumentNullException(nameof(runspaceInfos)); } if (runspaceInfos.GetLength(0) == 0) { - throw PSTraceSource.NewArgumentException("runspaceInfos"); + throw PSTraceSource.NewArgumentException(nameof(runspaceInfos)); } return false; diff --git a/src/System.Management.Automation/engine/remoting/common/RemoteSessionHyperVSocket.cs b/src/System.Management.Automation/engine/remoting/common/RemoteSessionHyperVSocket.cs index dff56e407f9..12bd7e1ad63 100644 --- a/src/System.Management.Automation/engine/remoting/common/RemoteSessionHyperVSocket.cs +++ b/src/System.Management.Automation/engine/remoting/common/RemoteSessionHyperVSocket.cs @@ -278,7 +278,7 @@ public RemoteSessionHyperVSocketServer(bool LoopbackMode) throw new PSInvalidOperationException( PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.RemoteSessionHyperVSocketServerConstructorFailure), ex, - PSRemotingErrorId.RemoteSessionHyperVSocketServerConstructorFailure.ToString(), + nameof(PSRemotingErrorId.RemoteSessionHyperVSocketServerConstructorFailure), ErrorCategory.InvalidOperation, null); } diff --git a/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs b/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs index 6c0e0625bdd..e8c546ff5e1 100644 --- a/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs +++ b/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs @@ -96,7 +96,7 @@ internal static string CreateProcessPipeName( { if (proc == null) { - throw new PSArgumentNullException("proc"); + throw new PSArgumentNullException(nameof(proc)); } if (string.IsNullOrEmpty(appDomainName)) @@ -453,7 +453,7 @@ internal RemoteSessionNamedPipeServer( { if (pipeName == null) { - throw new PSArgumentNullException("pipeName"); + throw new PSArgumentNullException(nameof(pipeName)); } _syncObject = new object(); @@ -481,11 +481,11 @@ private NamedPipeServerStream CreateNamedPipe( string coreName, CommonSecurityDescriptor securityDesc) { - if (serverName == null) { throw new PSArgumentNullException("serverName"); } + if (serverName == null) { throw new PSArgumentNullException(nameof(serverName)); } - if (namespaceName == null) { throw new PSArgumentNullException("namespaceName"); } + if (namespaceName == null) { throw new PSArgumentNullException(nameof(namespaceName)); } - if (coreName == null) { throw new PSArgumentNullException("coreName"); } + if (coreName == null) { throw new PSArgumentNullException(nameof(coreName)); } #if !UNIX string fullPipeName = @"\\" + serverName + @"\" + namespaceName + @"\" + coreName; @@ -682,7 +682,7 @@ internal void StartListening( { if (clientConnectCallback == null) { - throw new PSArgumentNullException("clientConnectCallback"); + throw new PSArgumentNullException(nameof(clientConnectCallback)); } lock (_syncObject) @@ -1177,7 +1177,7 @@ internal RemoteSessionNamedPipeClient( { if (pipeName == null) { - throw new PSArgumentNullException("pipeName"); + throw new PSArgumentNullException(nameof(pipeName)); } _pipeName = pipeName; @@ -1197,11 +1197,11 @@ internal RemoteSessionNamedPipeClient( string namespaceName, string coreName) { - if (serverName == null) { throw new PSArgumentNullException("serverName"); } + if (serverName == null) { throw new PSArgumentNullException(nameof(serverName)); } - if (namespaceName == null) { throw new PSArgumentNullException("namespaceName"); } + if (namespaceName == null) { throw new PSArgumentNullException(nameof(namespaceName)); } - if (coreName == null) { throw new PSArgumentNullException("coreName"); } + if (coreName == null) { throw new PSArgumentNullException(nameof(coreName)); } _pipeName = @"\\" + serverName + @"\" + namespaceName + @"\" + coreName; @@ -1283,7 +1283,7 @@ public ContainerSessionNamedPipeClient( { if (string.IsNullOrEmpty(containerObRoot)) { - throw new PSArgumentNullException("containerObRoot"); + throw new PSArgumentNullException(nameof(containerObRoot)); } // diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs index 8736f49050f..1ae89dfd4ef 100644 --- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs +++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs @@ -280,7 +280,7 @@ public virtual void SetSessionOptions(PSSessionOption options) { if (options == null) { - throw new ArgumentNullException("options"); + throw new ArgumentNullException(nameof(options)); } if (options.Culture != null) @@ -688,9 +688,9 @@ public AuthenticationMechanism ProxyAuthentication default: string message = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.ProxyAmbiguousAuthentication, value, - AuthenticationMechanism.Basic.ToString(), - AuthenticationMechanism.Negotiate.ToString(), - AuthenticationMechanism.Digest.ToString()); + nameof(AuthenticationMechanism.Basic), + nameof(AuthenticationMechanism.Negotiate), + nameof(AuthenticationMechanism.Digest)); throw new ArgumentException(message); } } @@ -974,7 +974,7 @@ public override void SetSessionOptions(PSSessionOption options) { if (options == null) { - throw new ArgumentNullException("options"); + throw new ArgumentNullException(nameof(options)); } if ((options.ProxyAccessType == ProxyAccessType.None) && (options.ProxyCredential != null)) @@ -1570,7 +1570,7 @@ public override AuthenticationMechanism AuthenticationMechanism if (value != AuthenticationMechanism.Default) { throw PSTraceSource.NewInvalidOperationException(RemotingErrorIdStrings.IPCSupportsOnlyDefaultAuth, - value.ToString(), AuthenticationMechanism.Default.ToString()); + value.ToString(), nameof(AuthenticationMechanism.Default)); } _authMechanism = value; @@ -1801,7 +1801,7 @@ public override AuthenticationMechanism AuthenticationMechanism if (value != Runspaces.AuthenticationMechanism.Default) { throw PSTraceSource.NewInvalidOperationException(RemotingErrorIdStrings.IPCSupportsOnlyDefaultAuth, - value.ToString(), AuthenticationMechanism.Default.ToString()); + value.ToString(), nameof(AuthenticationMechanism.Default)); } _authMechanism = value; @@ -1912,7 +1912,7 @@ public SSHConnectionInfo( string computerName, string keyFilePath) { - if (computerName == null) { throw new PSArgumentNullException("computerName"); } + if (computerName == null) { throw new PSArgumentNullException(nameof(computerName)); } this.UserName = userName; this.ComputerName = computerName; @@ -2740,7 +2740,7 @@ public override AuthenticationMechanism AuthenticationMechanism if (value != AuthenticationMechanism.Default) { throw PSTraceSource.NewInvalidOperationException(RemotingErrorIdStrings.IPCSupportsOnlyDefaultAuth, - value.ToString(), AuthenticationMechanism.Default.ToString()); + value.ToString(), nameof(AuthenticationMechanism.Default)); } _authMechanism = value; @@ -2864,7 +2864,7 @@ public override AuthenticationMechanism AuthenticationMechanism if (value != AuthenticationMechanism.Default) { throw PSTraceSource.NewInvalidOperationException(RemotingErrorIdStrings.IPCSupportsOnlyDefaultAuth, - value.ToString(), AuthenticationMechanism.Default.ToString()); + value.ToString(), nameof(AuthenticationMechanism.Default)); } _authMechanism = value; diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs index bfc4bdaca6b..85ba02b2e7b 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs @@ -1414,7 +1414,7 @@ internal static RemoteDataObject GeneratePowerShellInformational(ProgressRecord { if (progressRecord == null) { - throw PSTraceSource.NewArgumentNullException("progressRecord"); + throw PSTraceSource.NewArgumentNullException(nameof(progressRecord)); } return RemoteDataObject.CreateFrom(RemotingDestination.Client, @@ -1447,7 +1447,7 @@ internal static RemoteDataObject GeneratePowerShellInformational(InformationReco { if (informationRecord == null) { - throw PSTraceSource.NewArgumentNullException("informationRecord"); + throw PSTraceSource.NewArgumentNullException(nameof(informationRecord)); } return RemoteDataObject.CreateFrom(RemotingDestination.Client, @@ -1637,7 +1637,7 @@ private static T ConvertPropertyValueTo(string propertyName, object propertyV { if (propertyName == null) // comes from internal caller { - throw PSTraceSource.NewArgumentNullException("propertyName"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyName)); } if (typeof(T).IsEnum) @@ -1745,12 +1745,12 @@ private static PSPropertyInfo GetProperty(PSObject psObject, string propertyName { if (psObject == null) { - throw PSTraceSource.NewArgumentNullException("psObject"); + throw PSTraceSource.NewArgumentNullException(nameof(psObject)); } if (propertyName == null) { - throw PSTraceSource.NewArgumentNullException("propertyName"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyName)); } PSPropertyInfo property = psObject.Properties[propertyName]; @@ -1767,12 +1767,12 @@ internal static T GetPropertyValue(PSObject psObject, string propertyName) { if (psObject == null) { - throw PSTraceSource.NewArgumentNullException("psObject"); + throw PSTraceSource.NewArgumentNullException(nameof(psObject)); } if (propertyName == null) { - throw PSTraceSource.NewArgumentNullException("propertyName"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyName)); } PSPropertyInfo property = GetProperty(psObject, propertyName); @@ -1784,12 +1784,12 @@ internal static IEnumerable EnumerateListProperty(PSObject psObject, strin { if (psObject == null) { - throw PSTraceSource.NewArgumentNullException("psObject"); + throw PSTraceSource.NewArgumentNullException(nameof(psObject)); } if (propertyName == null) { - throw PSTraceSource.NewArgumentNullException("propertyName"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyName)); } IEnumerable e = GetPropertyValue(psObject, propertyName); @@ -1806,12 +1806,12 @@ internal static IEnumerable> EnumerateHashtable { if (psObject == null) { - throw PSTraceSource.NewArgumentNullException("psObject"); + throw PSTraceSource.NewArgumentNullException(nameof(psObject)); } if (propertyName == null) { - throw PSTraceSource.NewArgumentNullException("propertyName"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyName)); } Hashtable h = GetPropertyValue(psObject, propertyName); @@ -1836,7 +1836,7 @@ internal static RunspacePoolStateInfo GetRunspacePoolStateInfo(PSObject dataAsPS { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } RunspacePoolState state = GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.RunspaceState); @@ -1855,7 +1855,7 @@ internal static PSPrimitiveDictionary GetApplicationPrivateData(PSObject dataAsP { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.ApplicationPrivateData); @@ -1870,7 +1870,7 @@ internal static string GetPublicKey(PSObject dataAsPSObject) { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.PublicKey); @@ -1885,7 +1885,7 @@ internal static string GetEncryptedSessionKey(PSObject dataAsPSObject) { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.EncryptedSessionKey); @@ -1901,7 +1901,7 @@ internal static PSEventArgs GetPSEventArgs(PSObject dataAsPSObject) { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } int eventIdentifier = GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.PSEventArgsEventIdentifier); @@ -1941,7 +1941,7 @@ internal static int GetMinRunspaces(PSObject dataAsPSObject) { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.MinRunspaces); @@ -1957,7 +1957,7 @@ internal static int GetMaxRunspaces(PSObject dataAsPSObject) { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.MaxRunspaces); @@ -1973,7 +1973,7 @@ internal static PSPrimitiveDictionary GetApplicationArguments(PSObject dataAsPSO { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } // rehydration might not work yet (there is no type table before a runspace is created) @@ -1990,7 +1990,7 @@ internal static RunspacePoolInitInfo GetRunspacePoolInitInfo(PSObject dataAsPSOb { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } int maxRS = GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.MaxRunspaces); @@ -2009,7 +2009,7 @@ internal static PSThreadOptions GetThreadOptions(PSObject dataAsPSObject) { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.ThreadOptions); @@ -2025,7 +2025,7 @@ internal static HostInfo GetHostInfo(PSObject dataAsPSObject) { if (dataAsPSObject == null) { - throw PSTraceSource.NewArgumentNullException("dataAsPSObject"); + throw PSTraceSource.NewArgumentNullException(nameof(dataAsPSObject)); } PSObject propertyValue = GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.HostInfo); @@ -2109,7 +2109,7 @@ internal static ErrorRecord GetPowerShellError(object data) { if (data == null) { - throw PSTraceSource.NewArgumentNullException("data"); + throw PSTraceSource.NewArgumentNullException(nameof(data)); } PSObject dataAsPSObject = data as PSObject; @@ -2126,7 +2126,7 @@ internal static WarningRecord GetPowerShellWarning(object data) { if (data == null) { - throw PSTraceSource.NewArgumentNullException("data"); + throw PSTraceSource.NewArgumentNullException(nameof(data)); } return new WarningRecord((PSObject)data); @@ -2139,7 +2139,7 @@ internal static VerboseRecord GetPowerShellVerbose(object data) { if (data == null) { - throw PSTraceSource.NewArgumentNullException("data"); + throw PSTraceSource.NewArgumentNullException(nameof(data)); } return new VerboseRecord((PSObject)data); @@ -2152,7 +2152,7 @@ internal static DebugRecord GetPowerShellDebug(object data) { if (data == null) { - throw PSTraceSource.NewArgumentNullException("data"); + throw PSTraceSource.NewArgumentNullException(nameof(data)); } return new DebugRecord((PSObject)data); diff --git a/src/System.Management.Automation/engine/remoting/common/misc.cs b/src/System.Management.Automation/engine/remoting/common/misc.cs index ab344497f8b..e5b1f1edc04 100644 --- a/src/System.Management.Automation/engine/remoting/common/misc.cs +++ b/src/System.Management.Automation/engine/remoting/common/misc.cs @@ -17,7 +17,7 @@ internal RemoteSessionNegotiationEventArgs(RemoteSessionCapability remoteSession if (remoteSessionCapability == null) { - throw PSTraceSource.NewArgumentNullException("remoteSessionCapability"); + throw PSTraceSource.NewArgumentNullException(nameof(remoteSessionCapability)); } RemoteSessionCapability = remoteSessionCapability; @@ -50,7 +50,7 @@ internal RemoteDataEventArgs(RemoteDataObject receivedData) if (receivedData == null) { - throw PSTraceSource.NewArgumentNullException("receivedData"); + throw PSTraceSource.NewArgumentNullException(nameof(receivedData)); } ReceivedData = receivedData; @@ -314,7 +314,7 @@ internal RemoteSessionStateEventArgs(RemoteSessionStateInfo remoteSessionStateIn if (remoteSessionStateInfo == null) { - PSTraceSource.NewArgumentNullException("remoteSessionStateInfo"); + PSTraceSource.NewArgumentNullException(nameof(remoteSessionStateInfo)); } SessionStateInfo = remoteSessionStateInfo; diff --git a/src/System.Management.Automation/engine/remoting/common/remotingexceptions.cs b/src/System.Management.Automation/engine/remoting/common/remotingexceptions.cs index 47fb742f448..72f404bce10 100644 --- a/src/System.Management.Automation/engine/remoting/common/remotingexceptions.cs +++ b/src/System.Management.Automation/engine/remoting/common/remotingexceptions.cs @@ -475,7 +475,7 @@ protected PSRemotingTransportException(SerializationInfo info, StreamingContext { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } _errorCode = info.GetInt32("ErrorCode"); @@ -494,7 +494,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -618,7 +618,7 @@ protected PSRemotingTransportRedirectException(SerializationInfo info, Streaming { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } RedirectLocation = info.GetString("RedirectLocation"); @@ -659,7 +659,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs index 6ed7eb06245..555bc974d1b 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs @@ -528,7 +528,7 @@ private static Type LoadAndAnalyzeAssembly(string shellId, string applicationBas assembly = LoadSsnStateProviderAssembly(applicationBase, assemblyName); if (assembly == null) { - throw PSTraceSource.NewArgumentException("assemblyName", RemotingErrorIdStrings.UnableToLoadAssembly, + throw PSTraceSource.NewArgumentException(nameof(assemblyName), RemotingErrorIdStrings.UnableToLoadAssembly, assemblyName, ConfigurationDataFromXML.INITPARAMETERSTOKEN); } } @@ -545,7 +545,7 @@ private static Type LoadAndAnalyzeAssembly(string shellId, string applicationBas Type type = assembly.GetType(typeToLoad, true, true); if (type == null) { - throw PSTraceSource.NewArgumentException("typeToLoad", RemotingErrorIdStrings.UnableToLoadType, + throw PSTraceSource.NewArgumentException(nameof(typeToLoad), RemotingErrorIdStrings.UnableToLoadType, typeToLoad, ConfigurationDataFromXML.INITPARAMETERSTOKEN); } @@ -572,7 +572,7 @@ private static Type LoadAndAnalyzeAssembly(string shellId, string applicationBas // if we are here, that means we are unable to load the type specified // in the config xml.. notify the same. - throw PSTraceSource.NewArgumentException("typeToLoad", RemotingErrorIdStrings.UnableToLoadType, + throw PSTraceSource.NewArgumentException(nameof(typeToLoad), RemotingErrorIdStrings.UnableToLoadType, typeToLoad, ConfigurationDataFromXML.INITPARAMETERSTOKEN); } @@ -767,7 +767,7 @@ private static string { s_tracer.TraceError("Mandatory property {0} not specified for registry key {1}", name, registryKey.Name); - throw PSTraceSource.NewArgumentException("name", RemotingErrorIdStrings.MandatoryValueNotPresent, name, registryKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), RemotingErrorIdStrings.MandatoryValueNotPresent, name, registryKey.Name); } string s = value as string; @@ -775,7 +775,7 @@ private static string { s_tracer.TraceError("Value is null or empty for mandatory property {0} in {1}", name, registryKey.Name); - throw PSTraceSource.NewArgumentException("name", RemotingErrorIdStrings.MandatoryValueNotInCorrectFormat, name, registryKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), RemotingErrorIdStrings.MandatoryValueNotInCorrectFormat, name, registryKey.Name); } return s; @@ -812,13 +812,13 @@ public override InitialSessionState GetInitialSessionState(PSSenderInfo senderIn public override InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId) { if (sessionConfigurationData == null) - throw new ArgumentNullException("sessionConfigurationData"); + throw new ArgumentNullException(nameof(sessionConfigurationData)); if (senderInfo == null) - throw new ArgumentNullException("senderInfo"); + throw new ArgumentNullException(nameof(senderInfo)); if (configProviderId == null) - throw new ArgumentNullException("configProviderId"); + throw new ArgumentNullException(nameof(configProviderId)); InitialSessionState sessionState = InitialSessionState.CreateDefault2(); // now get all the modules in the specified path and import the same diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs index fd55cd51bd3..eefe68521b7 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -196,8 +196,8 @@ internal static void ProcessData(string data, DataProcessingDelegates callbacks) default: throw new PSRemotingTransportException(PSRemotingErrorId.IPCUnknownNodeType, RemotingErrorIdStrings.IPCUnknownNodeType, reader.NodeType.ToString(), - XmlNodeType.Element.ToString(), - XmlNodeType.EndElement.ToString()); + nameof(XmlNodeType.Element), + nameof(XmlNodeType.EndElement)); } } } @@ -903,7 +903,7 @@ private void OnRemoteSessionSendCompleted() private void OnDataPacketReceived(byte[] rawData, string stream, Guid psGuid) { string streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_STDOUT; - if (stream.Equals(DataPriorityType.PromptResponse.ToString(), StringComparison.OrdinalIgnoreCase)) + if (stream.Equals(nameof(DataPriorityType.PromptResponse), StringComparison.OrdinalIgnoreCase)) { streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_PROMPTRESPONSE; } @@ -1444,7 +1444,7 @@ internal VMHyperVSocketClientSessionTransportManager( { if (connectionInfo == null) { - throw new PSArgumentNullException("connectionInfo"); + throw new PSArgumentNullException(nameof(connectionInfo)); } _connectionInfo = connectionInfo; @@ -1478,7 +1478,7 @@ internal override void CreateAsync() throw new PSInvalidOperationException( PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.VMSessionConnectFailed), null, - PSRemotingErrorId.VMSessionConnectFailed.ToString(), + nameof(PSRemotingErrorId.VMSessionConnectFailed), ErrorCategory.InvalidOperation, null); } @@ -1492,7 +1492,7 @@ internal override void CreateAsync() throw new PSInvalidOperationException( PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.VMSessionConnectFailed), null, - PSRemotingErrorId.VMSessionConnectFailed.ToString(), + nameof(PSRemotingErrorId.VMSessionConnectFailed), ErrorCategory.InvalidOperation, null); } @@ -1527,7 +1527,7 @@ internal ContainerHyperVSocketClientSessionTransportManager( { if (connectionInfo == null) { - throw new PSArgumentNullException("connectionInfo"); + throw new PSArgumentNullException(nameof(connectionInfo)); } _connectionInfo = connectionInfo; @@ -1551,7 +1551,7 @@ internal override void CreateAsync() throw new PSInvalidOperationException( PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.ContainerSessionConnectFailed), null, - PSRemotingErrorId.ContainerSessionConnectFailed.ToString(), + nameof(PSRemotingErrorId.ContainerSessionConnectFailed), ErrorCategory.InvalidOperation, null); } @@ -1875,7 +1875,7 @@ internal NamedPipeClientSessionTransportManagerBase( { if (connectionInfo == null) { - throw new PSArgumentNullException("connectionInfo"); + throw new PSArgumentNullException(nameof(connectionInfo)); } _connectionInfo = connectionInfo; @@ -2000,7 +2000,7 @@ internal NamedPipeClientSessionTransportManager( { if (connectionInfo == null) { - throw new PSArgumentNullException("connectionInfo"); + throw new PSArgumentNullException(nameof(connectionInfo)); } _connectionInfo = connectionInfo; @@ -2067,7 +2067,7 @@ internal ContainerNamedPipeClientSessionTransportManager( { if (connectionInfo == null) { - throw new PSArgumentNullException("connectionInfo"); + throw new PSArgumentNullException(nameof(connectionInfo)); } _connectionInfo = connectionInfo; diff --git a/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs b/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs index e88447a61d7..a89f1a9d285 100644 --- a/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs +++ b/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs @@ -120,7 +120,7 @@ protected void ProcessingThreadStart(object state) protected void OnDataPacketReceived(byte[] rawData, string stream, Guid psGuid) { string streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_STDIN; - if (stream.Equals(DataPriorityType.PromptResponse.ToString(), StringComparison.OrdinalIgnoreCase)) + if (stream.Equals(nameof(DataPriorityType.PromptResponse), StringComparison.OrdinalIgnoreCase)) { streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_PROMPTRESPONSE; } @@ -603,7 +603,7 @@ private NamedPipeProcessMediator( { if (namedPipeServer == null) { - throw new PSArgumentNullException("namedPipeServer"); + throw new PSArgumentNullException(nameof(namedPipeServer)); } _namedPipeServer = namedPipeServer; diff --git a/src/System.Management.Automation/engine/remoting/server/ServerRemoteHostRawUserInterface.cs b/src/System.Management.Automation/engine/remoting/server/ServerRemoteHostRawUserInterface.cs index 5fe393171d3..1a709b11246 100644 --- a/src/System.Management.Automation/engine/remoting/server/ServerRemoteHostRawUserInterface.cs +++ b/src/System.Management.Automation/engine/remoting/server/ServerRemoteHostRawUserInterface.cs @@ -345,7 +345,7 @@ public override int LengthInBufferCells(string source) { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } return source.Length; @@ -356,7 +356,7 @@ public override int LengthInBufferCells(string source, int offset) { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } Dbg.Assert(offset >= 0, "offset >= 0"); diff --git a/src/System.Management.Automation/engine/remoting/server/ServerRemotingProtocol2.cs b/src/System.Management.Automation/engine/remoting/server/ServerRemotingProtocol2.cs index 15dc8654f88..56d41812a55 100644 --- a/src/System.Management.Automation/engine/remoting/server/ServerRemotingProtocol2.cs +++ b/src/System.Management.Automation/engine/remoting/server/ServerRemotingProtocol2.cs @@ -110,7 +110,7 @@ internal void ProcessReceivedData(RemoteDataObject receivedData) { if (receivedData == null) { - throw PSTraceSource.NewArgumentNullException("receivedData"); + throw PSTraceSource.NewArgumentNullException(nameof(receivedData)); } Dbg.Assert(receivedData.TargetInterface == RemotingTargetInterface.RunspacePool, @@ -617,7 +617,7 @@ internal void ProcessReceivedData(RemoteDataObject receivedData) { if (receivedData == null) { - throw PSTraceSource.NewArgumentNullException("receivedData"); + throw PSTraceSource.NewArgumentNullException(nameof(receivedData)); } Dbg.Assert(receivedData.TargetInterface == RemotingTargetInterface.PowerShell, diff --git a/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs b/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs index 36bbfb4bc08..04f7da23555 100644 --- a/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs +++ b/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs @@ -1846,17 +1846,17 @@ internal ServerRemoteDebugger( { if (driverInvoker == null) { - throw new PSArgumentNullException("driverInvoker"); + throw new PSArgumentNullException(nameof(driverInvoker)); } if (runspace == null) { - throw new PSArgumentNullException("runspace"); + throw new PSArgumentNullException(nameof(runspace)); } if (debugger == null) { - throw new PSArgumentNullException("debugger"); + throw new PSArgumentNullException(nameof(debugger)); } _driverInvoker = driverInvoker; diff --git a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs index e6520a9d389..1c239133313 100644 --- a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs +++ b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs @@ -298,14 +298,14 @@ internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataEven { if (dataEventArg == null) { - throw PSTraceSource.NewArgumentNullException("dataEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(dataEventArg)); } RemoteDataObject rcvdData = dataEventArg.ReceivedData; if (rcvdData == null) { - throw PSTraceSource.NewArgumentException("dataEventArg"); + throw PSTraceSource.NewArgumentException(nameof(dataEventArg)); } RemotingDestination destination = rcvdData.Destination; @@ -744,7 +744,7 @@ private void HandleCreateRunspacePool(object sender, RemoteDataEventArgs createR { if (createRunspaceEventArg == null) { - throw PSTraceSource.NewArgumentNullException("createRunspaceEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(createRunspaceEventArg)); } RemoteDataObject rcvdData = createRunspaceEventArg.ReceivedData; @@ -922,7 +922,7 @@ private void HandleNegotiationReceived(object sender, RemoteSessionNegotiationEv { if (negotiationEventArg == null) { - throw PSTraceSource.NewArgumentNullException("negotiationEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(negotiationEventArg)); } try diff --git a/src/System.Management.Automation/engine/remoting/server/serverremotesessionstatemachine.cs b/src/System.Management.Automation/engine/remoting/server/serverremotesessionstatemachine.cs index 27bd41330f1..2eae977a8da 100644 --- a/src/System.Management.Automation/engine/remoting/server/serverremotesessionstatemachine.cs +++ b/src/System.Management.Automation/engine/remoting/server/serverremotesessionstatemachine.cs @@ -71,7 +71,7 @@ internal ServerRemoteSessionDSHandlerStateMachine(ServerRemoteSession session) { if (session == null) { - throw PSTraceSource.NewArgumentNullException("session"); + throw PSTraceSource.NewArgumentNullException(nameof(session)); } _session = session; @@ -257,7 +257,7 @@ private void RaiseEventPrivate(RemoteSessionStateMachineEventArgs fsmEventArg) { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } EventHandler handler = _stateMachineHandle[(int)_state, (int)fsmEventArg.StateEvent]; @@ -291,7 +291,7 @@ private void DoCreateSession(object sender, RemoteSessionStateMachineEventArgs f { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.CreateSession, "StateEvent must be CreateSession"); @@ -320,7 +320,7 @@ private void DoNegotiationPending(object sender, RemoteSessionStateMachineEventA { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert((_state == RemoteSessionState.Idle) || (_state == RemoteSessionState.NegotiationSent), @@ -352,7 +352,7 @@ private void DoNegotiationReceived(object sender, RemoteSessionStateMachineEvent { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.NegotiationReceived, "StateEvent must be NegotiationReceived"); @@ -361,12 +361,12 @@ private void DoNegotiationReceived(object sender, RemoteSessionStateMachineEvent if (fsmEventArg.StateEvent != RemoteSessionEvent.NegotiationReceived) { - throw PSTraceSource.NewArgumentException("fsmEventArg"); + throw PSTraceSource.NewArgumentException(nameof(fsmEventArg)); } if (fsmEventArg.RemoteSessionCapability == null) { - throw PSTraceSource.NewArgumentException("fsmEventArg"); + throw PSTraceSource.NewArgumentException(nameof(fsmEventArg)); } SetState(RemoteSessionState.NegotiationReceived, null); @@ -390,7 +390,7 @@ private void DoNegotiationSending(object sender, RemoteSessionStateMachineEventA { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.NegotiationSending, "Event must be NegotiationSending"); @@ -419,7 +419,7 @@ private void DoNegotiationCompleted(object sender, RemoteSessionStateMachineEven { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(_state == RemoteSessionState.NegotiationSending, "State must be NegotiationSending"); @@ -447,7 +447,7 @@ private void DoEstablished(object sender, RemoteSessionStateMachineEventArgs fsm { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(_state == RemoteSessionState.NegotiationSent, "State must be NegotiationReceived"); @@ -455,7 +455,7 @@ private void DoEstablished(object sender, RemoteSessionStateMachineEventArgs fsm if (fsmEventArg.StateEvent != RemoteSessionEvent.NegotiationCompleted) { - throw PSTraceSource.NewArgumentException("fsmEventArg"); + throw PSTraceSource.NewArgumentException(nameof(fsmEventArg)); } if (_state != RemoteSessionState.NegotiationSent) @@ -487,12 +487,12 @@ internal void DoMessageReceived(object sender, RemoteSessionStateMachineEventArg { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } if (fsmEventArg.RemoteData == null) { - throw PSTraceSource.NewArgumentException("fsmEventArg"); + throw PSTraceSource.NewArgumentException(nameof(fsmEventArg)); } Dbg.Assert(_state == RemoteSessionState.Established || @@ -592,14 +592,14 @@ private void DoConnectFailed(object sender, RemoteSessionStateMachineEventArgs f { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.ConnectFailed, "StateEvent must be ConnectFailed"); if (fsmEventArg.StateEvent != RemoteSessionEvent.ConnectFailed) { - throw PSTraceSource.NewArgumentException("fsmEventArg"); + throw PSTraceSource.NewArgumentException(nameof(fsmEventArg)); } Dbg.Assert(_state == RemoteSessionState.Connecting, "session State must be Connecting"); @@ -629,14 +629,14 @@ private void DoFatalError(object sender, RemoteSessionStateMachineEventArgs fsmE { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.FatalError, "StateEvent must be FatalError"); if (fsmEventArg.StateEvent != RemoteSessionEvent.FatalError) { - throw PSTraceSource.NewArgumentException("fsmEventArg"); + throw PSTraceSource.NewArgumentException(nameof(fsmEventArg)); } DoClose(this, fsmEventArg); @@ -674,7 +674,7 @@ private void DoClose(object sender, RemoteSessionStateMachineEventArgs fsmEventA { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } RemoteSessionState oldState = _state; @@ -728,7 +728,7 @@ private void DoCloseFailed(object sender, RemoteSessionStateMachineEventArgs fsm { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.CloseFailed, "StateEvent must be CloseFailed"); @@ -758,7 +758,7 @@ private void DoCloseCompleted(object sender, RemoteSessionStateMachineEventArgs { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.CloseCompleted, "StateEvent must be CloseCompleted"); @@ -788,7 +788,7 @@ private void DoNegotiationFailed(object sender, RemoteSessionStateMachineEventAr { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.NegotiationFailed, "StateEvent must be NegotiationFailed"); @@ -817,7 +817,7 @@ private void DoNegotiationTimeout(object sender, RemoteSessionStateMachineEventA { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.NegotiationTimeout, "StateEvent must be NegotiationTimeout"); @@ -852,7 +852,7 @@ private void DoSendFailed(object sender, RemoteSessionStateMachineEventArgs fsmE { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.SendFailed, "StateEvent must be SendFailed"); @@ -881,7 +881,7 @@ private void DoReceiveFailed(object sender, RemoteSessionStateMachineEventArgs f { if (fsmEventArg == null) { - throw PSTraceSource.NewArgumentNullException("fsmEventArg"); + throw PSTraceSource.NewArgumentNullException(nameof(fsmEventArg)); } Dbg.Assert(fsmEventArg.StateEvent == RemoteSessionEvent.ReceiveFailed, "StateEvent must be ReceivedFailed"); diff --git a/src/System.Management.Automation/engine/remoting/server/serverremotingprotocolimplementation.cs b/src/System.Management.Automation/engine/remoting/server/serverremotingprotocolimplementation.cs index 653299e2cbb..1e72be279c7 100644 --- a/src/System.Management.Automation/engine/remoting/server/serverremotingprotocolimplementation.cs +++ b/src/System.Management.Automation/engine/remoting/server/serverremotingprotocolimplementation.cs @@ -172,7 +172,7 @@ internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg) { if (dataArg == null) { - throw PSTraceSource.NewArgumentNullException("dataArg"); + throw PSTraceSource.NewArgumentNullException(nameof(dataArg)); } RemoteDataObject rcvdData = dataArg.ReceivedData; diff --git a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs index 2341dca4042..5ffa9cf1af4 100644 --- a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs +++ b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs @@ -2154,7 +2154,7 @@ private ScriptBlockSerializationHelper(SerializationInfo info, StreamingContext _scriptText = info.GetValue("ScriptText", typeof(string)) as string; if (_scriptText == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } } diff --git a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs index 8ae6da58655..7077ebeacbe 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs @@ -2538,7 +2538,7 @@ internal static object Where(IEnumerator enumerator, ScriptBlock expressionSB, W if (numberToReturn < 0) { - throw new ArgumentOutOfRangeException("numberToReturn", numberToReturn, ParserStrings.NumberToReturnMustBeGreaterThanZero); + throw new ArgumentOutOfRangeException(nameof(numberToReturn), numberToReturn, ParserStrings.NumberToReturnMustBeGreaterThanZero); } var context = Runspace.DefaultRunspace.ExecutionContext; @@ -2771,7 +2771,7 @@ internal static object ForEach(IEnumerator enumerator, object expression, object Diagnostics.Assert(arguments != null, "The ForEach() operator should never receive a null value for the 'arguments' parameter from the runtime."); if (expression == null) { - throw new ArgumentNullException("expression"); + throw new ArgumentNullException(nameof(expression)); } var context = Runspace.DefaultRunspace.ExecutionContext; diff --git a/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs b/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs index 1f0c26ab01a..0c4658cc14d 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs @@ -31,7 +31,7 @@ internal static string Multiply(string s, int times) if (times < 0) { // TODO: this should be a runtime error. - throw new ArgumentOutOfRangeException("times"); + throw new ArgumentOutOfRangeException(nameof(times)); } if (times == 0 || s.Length == 0) diff --git a/src/System.Management.Automation/engine/serialization.cs b/src/System.Management.Automation/engine/serialization.cs index ddc44bd8970..1b17a39a4a7 100644 --- a/src/System.Management.Automation/engine/serialization.cs +++ b/src/System.Management.Automation/engine/serialization.cs @@ -218,12 +218,12 @@ internal Serializer(XmlWriter writer, SerializationContext context) { if (writer == null) { - throw PSTraceSource.NewArgumentException("writer"); + throw PSTraceSource.NewArgumentException(nameof(writer)); } if (context == null) { - throw PSTraceSource.NewArgumentException("context"); + throw PSTraceSource.NewArgumentException(nameof(context)); } _serializer = new InternalSerializer(writer, context); @@ -484,7 +484,7 @@ internal Deserializer(XmlReader reader, DeserializationContext context) { if (reader == null) { - throw PSTraceSource.NewArgumentNullException("reader"); + throw PSTraceSource.NewArgumentNullException(nameof(reader)); } _reader = reader; @@ -666,7 +666,7 @@ internal static bool IsInstanceOfType(object o, Type type) { if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } if (o == null) @@ -687,7 +687,7 @@ internal static bool IsDeserializedInstanceOfType(object o, Type type) { if (type == null) { - throw PSTraceSource.NewArgumentNullException("type"); + throw PSTraceSource.NewArgumentNullException(nameof(type)); } if (o == null) @@ -3110,7 +3110,7 @@ private object ReadOneDeserializedObject(out string streamName, out bool isKnown if (_reader.NodeType != XmlNodeType.Element) { throw NewXmlException(Serialization.InvalidNodeType, null, - _reader.NodeType.ToString(), XmlNodeType.Element.ToString()); + _reader.NodeType.ToString(), nameof(XmlNodeType.Element)); } s_trace.WriteLine("Processing start node {0}", _reader.LocalName); @@ -5905,7 +5905,7 @@ public PSPrimitiveDictionary(Hashtable other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } foreach (DictionaryEntry entry in other) @@ -6691,14 +6691,14 @@ public override object ConvertFrom(PSObject sourceValue, Type destinationType, I { if (destinationType == null) { - throw PSTraceSource.NewArgumentNullException("destinationType"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationType)); } if (sourceValue == null) { throw new PSInvalidCastException( "InvalidCastWhenRehydratingFromNull", - PSTraceSource.NewArgumentNullException("sourceValue"), + PSTraceSource.NewArgumentNullException(nameof(sourceValue)), ExtendedTypeSystem.InvalidCastFromNull, destinationType.ToString()); } @@ -7274,13 +7274,13 @@ public static UInt32 GetParameterSetMetadataFlags(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } ParameterSetMetadata parameterSetMetadata = instance.BaseObject as ParameterSetMetadata; if (parameterSetMetadata == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } return (UInt32)(parameterSetMetadata.Flags); @@ -7296,13 +7296,13 @@ public static PSObject GetInvocationInfo(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } DebuggerStopEventArgs dbgStopEventArgs = instance.BaseObject as DebuggerStopEventArgs; if (dbgStopEventArgs == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } if (dbgStopEventArgs.InvocationInfo == null) @@ -7474,7 +7474,7 @@ private static CustomItemBase RehydrateCustomItemBase(PSObject deserializedItem) } else { - throw PSTraceSource.NewArgumentException("deserializedItem"); + throw PSTraceSource.NewArgumentException(nameof(deserializedItem)); } return result; @@ -7556,13 +7556,13 @@ public static Guid GetFormatViewDefinitionInstanceId(PSObject instance) { if (instance == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } FormatViewDefinition formatViewDefinition = instance.BaseObject as FormatViewDefinition; if (formatViewDefinition == null) { - throw PSTraceSource.NewArgumentNullException("instance"); + throw PSTraceSource.NewArgumentNullException(nameof(instance)); } return formatViewDefinition.InstanceId; diff --git a/src/System.Management.Automation/help/CommandHelpProvider.cs b/src/System.Management.Automation/help/CommandHelpProvider.cs index e89bbcc40c4..52e6b3e2916 100644 --- a/src/System.Management.Automation/help/CommandHelpProvider.cs +++ b/src/System.Management.Automation/help/CommandHelpProvider.cs @@ -566,7 +566,7 @@ private string FindHelpFile(CmdletInfo cmdletInfo) if (cmdletInfo == null) { - throw PSTraceSource.NewArgumentNullException("cmdletInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(cmdletInfo)); } // Get the help file name from the cmdlet metadata diff --git a/src/System.Management.Automation/help/HelpCategoryInvalidException.cs b/src/System.Management.Automation/help/HelpCategoryInvalidException.cs index 194160ad5e2..4d2a8100d0c 100644 --- a/src/System.Management.Automation/help/HelpCategoryInvalidException.cs +++ b/src/System.Management.Automation/help/HelpCategoryInvalidException.cs @@ -128,7 +128,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/help/HelpNotFoundException.cs b/src/System.Management.Automation/help/HelpNotFoundException.cs index e6dc7a21ee4..355be44fd7c 100644 --- a/src/System.Management.Automation/help/HelpNotFoundException.cs +++ b/src/System.Management.Automation/help/HelpNotFoundException.cs @@ -134,7 +134,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/help/ProviderHelpProvider.cs b/src/System.Management.Automation/help/ProviderHelpProvider.cs index a21c3038b43..a7d92f58f24 100644 --- a/src/System.Management.Automation/help/ProviderHelpProvider.cs +++ b/src/System.Management.Automation/help/ProviderHelpProvider.cs @@ -149,7 +149,7 @@ private void LoadHelpFile(ProviderInfo providerInfo) { if (providerInfo == null) { - throw PSTraceSource.NewArgumentNullException("providerInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInfo)); } string helpFile = providerInfo.HelpFile; diff --git a/src/System.Management.Automation/logging/MshLog.cs b/src/System.Management.Automation/logging/MshLog.cs index 9ebdb699e40..23c687b58ee 100644 --- a/src/System.Management.Automation/logging/MshLog.cs +++ b/src/System.Management.Automation/logging/MshLog.cs @@ -101,7 +101,7 @@ private static IEnumerable GetLogProvider(ExecutionContext executio { if (executionContext == null) { - throw PSTraceSource.NewArgumentNullException("executionContext"); + throw PSTraceSource.NewArgumentNullException(nameof(executionContext)); } string shellId = executionContext.ShellID; @@ -205,13 +205,13 @@ internal static void LogEngineHealthEvent(ExecutionContext executionContext, { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } if (exception == null) { - PSTraceSource.NewArgumentNullException("exception"); + PSTraceSource.NewArgumentNullException(nameof(exception)); return; } @@ -320,13 +320,13 @@ Dictionary additionalInfo { if (logContext == null) { - PSTraceSource.NewArgumentNullException("logContext"); + PSTraceSource.NewArgumentNullException(nameof(logContext)); return; } if (exception == null) { - PSTraceSource.NewArgumentNullException("exception"); + PSTraceSource.NewArgumentNullException(nameof(exception)); return; } @@ -359,7 +359,7 @@ internal static void LogEngineLifecycleEvent(ExecutionContext executionContext, { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } @@ -407,13 +407,13 @@ Severity severity { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } if (exception == null) { - PSTraceSource.NewArgumentNullException("exception"); + PSTraceSource.NewArgumentNullException(nameof(exception)); return; } @@ -448,13 +448,13 @@ internal static void LogCommandLifecycleEvent(ExecutionContext executionContext, { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } if (invocationInfo == null) { - PSTraceSource.NewArgumentNullException("invocationInfo"); + PSTraceSource.NewArgumentNullException(nameof(invocationInfo)); return; } @@ -490,7 +490,7 @@ internal static void LogCommandLifecycleEvent(ExecutionContext executionContext, { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } @@ -531,7 +531,7 @@ internal static void LogPipelineExecutionDetailEvent(ExecutionContext executionC { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } @@ -562,7 +562,7 @@ internal static void LogPipelineExecutionDetailEvent(ExecutionContext executionC { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } @@ -598,13 +598,13 @@ Severity severity { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } if (exception == null) { - PSTraceSource.NewArgumentNullException("exception"); + PSTraceSource.NewArgumentNullException(nameof(exception)); return; } @@ -639,7 +639,7 @@ internal static void LogProviderLifecycleEvent(ExecutionContext executionContext { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } @@ -675,7 +675,7 @@ internal static void LogSettingsEvent(ExecutionContext executionContext, { if (executionContext == null) { - PSTraceSource.NewArgumentNullException("executionContext"); + PSTraceSource.NewArgumentNullException(nameof(executionContext)); return; } diff --git a/src/System.Management.Automation/namespaces/AliasProvider.cs b/src/System.Management.Automation/namespaces/AliasProvider.cs index 700d2a7ce84..d6b99155630 100644 --- a/src/System.Management.Automation/namespaces/AliasProvider.cs +++ b/src/System.Management.Automation/namespaces/AliasProvider.cs @@ -244,7 +244,7 @@ internal override void SetSessionStateItem(string name, object value, bool write break; } - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException(nameof(value)); } while (false); } diff --git a/src/System.Management.Automation/namespaces/CoreCommandContext.cs b/src/System.Management.Automation/namespaces/CoreCommandContext.cs index 4c571a6fb73..34cdb0d68b7 100644 --- a/src/System.Management.Automation/namespaces/CoreCommandContext.cs +++ b/src/System.Management.Automation/namespaces/CoreCommandContext.cs @@ -54,7 +54,7 @@ internal CmdletProviderContext(ExecutionContext executionContext) { if (executionContext == null) { - throw PSTraceSource.NewArgumentNullException("executionContext"); + throw PSTraceSource.NewArgumentNullException(nameof(executionContext)); } ExecutionContext = executionContext; @@ -84,7 +84,7 @@ internal CmdletProviderContext(ExecutionContext executionContext, CommandOrigin { if (executionContext == null) { - throw PSTraceSource.NewArgumentNullException("executionContext"); + throw PSTraceSource.NewArgumentNullException(nameof(executionContext)); } ExecutionContext = executionContext; @@ -118,7 +118,7 @@ internal CmdletProviderContext( // verify the command parameter if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } _command = command; @@ -172,7 +172,7 @@ internal CmdletProviderContext( // verify the command parameter if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } _command = command; @@ -220,7 +220,7 @@ internal CmdletProviderContext( // verify the command parameter if (command == null) { - throw PSTraceSource.NewArgumentNullException("command"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } _command = command; @@ -256,7 +256,7 @@ internal CmdletProviderContext( { if (contextToCopyFrom == null) { - throw PSTraceSource.NewArgumentNullException("contextToCopyFrom"); + throw PSTraceSource.NewArgumentNullException(nameof(contextToCopyFrom)); } ExecutionContext = contextToCopyFrom.ExecutionContext; @@ -985,7 +985,7 @@ internal void WriteErrorsToContext(CmdletProviderContext errorContext) { if (errorContext == null) { - throw PSTraceSource.NewArgumentNullException("errorContext"); + throw PSTraceSource.NewArgumentNullException(nameof(errorContext)); } if (HasErrors()) diff --git a/src/System.Management.Automation/namespaces/FileSystemContentStream.cs b/src/System.Management.Automation/namespaces/FileSystemContentStream.cs index da2d708aa99..fc60be64a41 100644 --- a/src/System.Management.Automation/namespaces/FileSystemContentStream.cs +++ b/src/System.Management.Automation/namespaces/FileSystemContentStream.cs @@ -156,7 +156,7 @@ public FileSystemContentReaderWriter( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (s_tracer.IsEnabled) @@ -435,7 +435,7 @@ internal void SeekItemsBackward(int backCount) if (backCount < 0) { // The caller needs to guarantee that 'backCount' is greater or equals to 0 - throw PSTraceSource.NewArgumentException("backCount"); + throw PSTraceSource.NewArgumentException(nameof(backCount)); } if (_isRawStream && _waitForChanges) @@ -1088,7 +1088,7 @@ private void WriteObject(object content) } catch (InvalidCastException) { - throw PSTraceSource.NewArgumentException("content", FileSystemProviderStrings.ByteEncodingError); + throw PSTraceSource.NewArgumentException(nameof(content), FileSystemProviderStrings.ByteEncodingError); } } else diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 3c35e1bab60..081e51228b6 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -507,7 +507,7 @@ protected override PSDriveInfo NewDrive(PSDriveInfo drive) // verify parameters if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } if (string.IsNullOrEmpty(drive.Root)) @@ -1260,7 +1260,7 @@ protected override void GetItem(string path) if (string.IsNullOrEmpty(path)) { // The parameter was null, throw an exception - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } try @@ -1446,7 +1446,7 @@ protected override void InvokeDefaultAction(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -1628,7 +1628,7 @@ private void GetPathItems( // Verify parameters if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -2114,14 +2114,14 @@ protected override void RenameItem( // Check the parameters if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); if (string.IsNullOrEmpty(newName)) { - throw PSTraceSource.NewArgumentException("newName"); + throw PSTraceSource.NewArgumentException(nameof(newName)); } // Clean up "newname" to fix some common usability problems: @@ -2141,7 +2141,7 @@ protected override void RenameItem( // If a path is specified for the newName then we flag that as an error. if (string.Compare(Path.GetFileName(newName), newName, StringComparison.OrdinalIgnoreCase) != 0) { - throw PSTraceSource.NewArgumentException("newName", FileSystemProviderStrings.RenameError); + throw PSTraceSource.NewArgumentException(nameof(newName), FileSystemProviderStrings.RenameError); } // Verify that the target doesn't represent a device name @@ -2255,7 +2255,7 @@ protected override void NewItem( // Verify parameters if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (string.IsNullOrEmpty(type)) @@ -2351,7 +2351,7 @@ protected override void NewItem( if (string.IsNullOrEmpty(strTargetPath)) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } bool exists = false; @@ -2663,7 +2663,7 @@ protected override void NewItem( } else { - throw PSTraceSource.NewArgumentException("type", FileSystemProviderStrings.UnknownType); + throw PSTraceSource.NewArgumentException(nameof(type), FileSystemProviderStrings.UnknownType); } } @@ -2822,7 +2822,7 @@ private bool CreateIntermediateDirectories(string path) if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } try @@ -2912,7 +2912,7 @@ protected override void RemoveItem(string path, bool recurse) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } try @@ -3385,7 +3385,7 @@ private bool ItemExists(string path, out ErrorRecord error) if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } bool result = false; @@ -3486,7 +3486,7 @@ protected override bool HasChildItems(string path) // verify parameters if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -3588,12 +3588,12 @@ protected override void CopyItem( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (string.IsNullOrEmpty(destinationPath)) { - throw PSTraceSource.NewArgumentException("destinationPath"); + throw PSTraceSource.NewArgumentException(nameof(destinationPath)); } path = NormalizePath(path); @@ -4367,14 +4367,14 @@ private bool PerformCopyFileFromRemoteSession(string sourceFileFullName, FileInf ps.AddParameter("copyFromNumBytes", fragmentSize); if (force) { - ps.AddParameter("force", true); + ps.AddParameter(nameof(force), true); } #if !UNIX if (isAlternateDataStream) { ps.AddParameter("isAlternateStream", true); - ps.AddParameter("streamName", streamName); + ps.AddParameter(nameof(streamName), streamName); } #endif @@ -4528,7 +4528,7 @@ private string MakeRemotePath(System.Management.Automation.PowerShell ps, string string path = null; ps.AddCommand(CopyFileRemoteUtils.PSCopyToSessionHelperName); - ps.AddParameter("remotePath", remotePath); + ps.AddParameter(nameof(remotePath), remotePath); Hashtable op = SafeInvokeCommand.Invoke(ps, this, null); if (op != null) @@ -4689,7 +4689,7 @@ private bool CopyFileStreamToRemoteSession(FileInfo file, string destinationPath ps.AddCommand(CopyFileRemoteUtils.PSCopyToSessionHelperName); ps.AddParameter("copyToFilePath", destinationPath); ps.AddParameter("b64Fragment", b64Fragment); - ps.AddParameter("streamName", streamName); + ps.AddParameter(nameof(streamName), streamName); } Hashtable op = SafeInvokeCommand.Invoke(ps, this, null); @@ -4843,7 +4843,7 @@ private string CreateDirectoryOnRemoteSession(string destination, bool force, Sy ps.AddParameter("createDirectoryPath", destination); if (force) { - ps.AddParameter("force", true); + ps.AddParameter(nameof(force), true); } Hashtable op = SafeInvokeCommand.Invoke(ps, this, null); @@ -5050,7 +5050,7 @@ protected override string NormalizeRelativePath( { if (string.IsNullOrEmpty(path) || !IsValidPath(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (basePath == null) @@ -5237,7 +5237,7 @@ private string NormalizeRelativePathHelper(string path, string basePath) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (path.Length == 0) @@ -5661,7 +5661,7 @@ protected override string GetChildName(string path) if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } // Normalize the path @@ -5724,7 +5724,7 @@ protected override bool IsItemContainer(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -5758,12 +5758,12 @@ protected override void MoveItem( if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (string.IsNullOrEmpty(destination)) { - throw PSTraceSource.NewArgumentException("destination"); + throw PSTraceSource.NewArgumentException(nameof(destination)); } path = NormalizePath(path); @@ -6122,7 +6122,7 @@ public void GetProperty(string path, Collection providerSpecificPickList { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -6255,12 +6255,12 @@ public void SetProperty(string path, PSObject propertyToSet) if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (propertyToSet == null) { - throw PSTraceSource.NewArgumentNullException("propertyToSet"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyToSet)); } path = NormalizePath(path); @@ -6426,7 +6426,7 @@ public void ClearProperty( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -6434,14 +6434,14 @@ public void ClearProperty( if (propertiesToClear == null || propertiesToClear.Count == 0) { - throw PSTraceSource.NewArgumentNullException("propertiesToClear"); + throw PSTraceSource.NewArgumentNullException(nameof(propertiesToClear)); } // Only the attributes property can be cleared if (propertiesToClear.Count > 1 || Host.CurrentCulture.CompareInfo.Compare("Attributes", propertiesToClear[0], CompareOptions.IgnoreCase) != 0) { - throw PSTraceSource.NewArgumentException("propertiesToClear", FileSystemProviderStrings.CannotClearProperty); + throw PSTraceSource.NewArgumentException(nameof(propertiesToClear), FileSystemProviderStrings.CannotClearProperty); } try @@ -6544,7 +6544,7 @@ public IContentReader GetContentReader(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -6718,7 +6718,7 @@ public IContentWriter GetContentWriter(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -6847,7 +6847,7 @@ public void ClearContent(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); @@ -8455,12 +8455,12 @@ private static bool WinCreateJunction(string path, string target) } else { - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); } } else { - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); } } @@ -8535,7 +8535,7 @@ public static class AlternateDataStreamUtilities /// The list of streams (and their size) in the file. internal static List GetStreams(string path) { - if (path == null) throw new ArgumentNullException("path"); + if (path == null) throw new ArgumentNullException(nameof(path)); List alternateStreams = new List(); @@ -8648,8 +8648,8 @@ internal static bool TryCreateFileStream(string path, string streamName, FileMod /// The name of the alternate data stream to delete. internal static void DeleteFileStream(string path, string streamName) { - if (path == null) throw new ArgumentNullException("path"); - if (streamName == null) throw new ArgumentNullException("streamName"); + if (path == null) throw new ArgumentNullException(nameof(path)); + if (streamName == null) throw new ArgumentNullException(nameof(streamName)); string adjustedStreamName = streamName.Trim(); if (adjustedStreamName.IndexOf(':') != 0) diff --git a/src/System.Management.Automation/namespaces/FileSystemSecurity.cs b/src/System.Management.Automation/namespaces/FileSystemSecurity.cs index 25143673900..8a95b16ee8b 100644 --- a/src/System.Management.Automation/namespaces/FileSystemSecurity.cs +++ b/src/System.Management.Automation/namespaces/FileSystemSecurity.cs @@ -46,12 +46,12 @@ public void GetSecurityDescriptor(string path, if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if ((sections & ~AccessControlSections.All) != 0) { - throw PSTraceSource.NewArgumentException("sections"); + throw PSTraceSource.NewArgumentException(nameof(sections)); } var currentPrivilegeState = new PlatformInvokes.TOKEN_PRIVILEGE(); @@ -103,14 +103,14 @@ public void SetSecurityDescriptor( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } path = NormalizePath(path); if (securityDescriptor == null) { - throw PSTraceSource.NewArgumentNullException("securityDescriptor"); + throw PSTraceSource.NewArgumentNullException(nameof(securityDescriptor)); } if (!File.Exists(path) && !Directory.Exists(path)) @@ -123,7 +123,7 @@ public void SetSecurityDescriptor( if (sd == null) { - throw PSTraceSource.NewArgumentException("securityDescriptor"); + throw PSTraceSource.NewArgumentException(nameof(securityDescriptor)); } else { diff --git a/src/System.Management.Automation/namespaces/FunctionProvider.cs b/src/System.Management.Automation/namespaces/FunctionProvider.cs index d12808cf7c0..47db2f63adb 100644 --- a/src/System.Management.Automation/namespaces/FunctionProvider.cs +++ b/src/System.Management.Automation/namespaces/FunctionProvider.cs @@ -238,7 +238,7 @@ internal override void SetSessionStateItem(string name, object value, bool write break; } - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException(nameof(value)); } while (false); if (writeItem && modifiedItem != null) diff --git a/src/System.Management.Automation/namespaces/LocationGlobber.cs b/src/System.Management.Automation/namespaces/LocationGlobber.cs index 0a4e1785e4c..ab43d492d8f 100644 --- a/src/System.Management.Automation/namespaces/LocationGlobber.cs +++ b/src/System.Management.Automation/namespaces/LocationGlobber.cs @@ -2387,7 +2387,7 @@ private static string ParseProviderPath(string path, out string providerId) { ArgumentException e = PSTraceSource.NewArgumentException( - "path", + nameof(path), SessionStateStrings.NotProviderQualifiedPath); throw e; } diff --git a/src/System.Management.Automation/namespaces/NavigationProviderBase.cs b/src/System.Management.Automation/namespaces/NavigationProviderBase.cs index bacaa547a60..9bb1e3813b5 100644 --- a/src/System.Management.Automation/namespaces/NavigationProviderBase.cs +++ b/src/System.Management.Automation/namespaces/NavigationProviderBase.cs @@ -407,7 +407,7 @@ protected virtual string GetParentPath(string path, string root) if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (root == null) @@ -508,7 +508,7 @@ internal string ContractRelativePath( if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (path.Length == 0) @@ -706,7 +706,7 @@ protected virtual string GetChildName(string path) if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } // Normalize the path @@ -1039,7 +1039,7 @@ private static Stack NormalizeThePath( PSArgumentException e = (PSArgumentException) PSTraceSource.NewArgumentException( - "path", + nameof(path), SessionStateStrings.NormalizeRelativePathOutsideBase, path, basePath); diff --git a/src/System.Management.Automation/namespaces/ProviderBase.cs b/src/System.Management.Automation/namespaces/ProviderBase.cs index 9441cf90e75..22bd599f637 100644 --- a/src/System.Management.Automation/namespaces/ProviderBase.cs +++ b/src/System.Management.Automation/namespaces/ProviderBase.cs @@ -98,7 +98,7 @@ internal void SetProviderInformation(ProviderInfo providerInfoToSet) { if (providerInfoToSet == null) { - throw PSTraceSource.NewArgumentNullException("providerInfoToSet"); + throw PSTraceSource.NewArgumentNullException(nameof(providerInfoToSet)); } _providerInformation = providerInfoToSet; @@ -1425,12 +1425,12 @@ public virtual string GetResourceString(string baseName, string resourceId) { if (string.IsNullOrEmpty(baseName)) { - throw PSTraceSource.NewArgumentException("baseName"); + throw PSTraceSource.NewArgumentException(nameof(baseName)); } if (string.IsNullOrEmpty(resourceId)) { - throw PSTraceSource.NewArgumentException("resourceId"); + throw PSTraceSource.NewArgumentException(nameof(resourceId)); } ResourceManager manager = @@ -1447,12 +1447,12 @@ public virtual string GetResourceString(string baseName, string resourceId) } catch (MissingManifestResourceException) { - throw PSTraceSource.NewArgumentException("baseName", GetErrorText.ResourceBaseNameFailure, baseName); + throw PSTraceSource.NewArgumentException(nameof(baseName), GetErrorText.ResourceBaseNameFailure, baseName); } if (retValue == null) { - throw PSTraceSource.NewArgumentException("resourceId", GetErrorText.ResourceIdFailure, resourceId); + throw PSTraceSource.NewArgumentException(nameof(resourceId), GetErrorText.ResourceIdFailure, resourceId); } return retValue; @@ -1468,7 +1468,7 @@ public void ThrowTerminatingError(ErrorRecord errorRecord) { if (errorRecord == null) { - throw PSTraceSource.NewArgumentNullException("errorRecord"); + throw PSTraceSource.NewArgumentNullException(nameof(errorRecord)); } if (errorRecord.ErrorDetails != null @@ -1677,7 +1677,7 @@ public void WriteProgress(ProgressRecord progressRecord) if (progressRecord == null) { - throw PSTraceSource.NewArgumentNullException("progressRecord"); + throw PSTraceSource.NewArgumentNullException(nameof(progressRecord)); } Context.WriteProgress(progressRecord); @@ -1801,7 +1801,7 @@ private PSObject WrapOutputInPSObject( { if (item == null) { - throw PSTraceSource.NewArgumentNullException("item"); + throw PSTraceSource.NewArgumentNullException(nameof(item)); } PSObject result = new PSObject(item); @@ -2000,7 +2000,7 @@ public void WriteError(ErrorRecord errorRecord) if (errorRecord == null) { - throw PSTraceSource.NewArgumentNullException("errorRecord"); + throw PSTraceSource.NewArgumentNullException(nameof(errorRecord)); } if (errorRecord.ErrorDetails != null diff --git a/src/System.Management.Automation/namespaces/ProviderDeclarationAttribute.cs b/src/System.Management.Automation/namespaces/ProviderDeclarationAttribute.cs index 4107dc662c6..dbc03a69181 100644 --- a/src/System.Management.Automation/namespaces/ProviderDeclarationAttribute.cs +++ b/src/System.Management.Automation/namespaces/ProviderDeclarationAttribute.cs @@ -37,13 +37,13 @@ public CmdletProviderAttribute( if (string.IsNullOrEmpty(providerName)) { - throw PSTraceSource.NewArgumentNullException("providerName"); + throw PSTraceSource.NewArgumentNullException(nameof(providerName)); } if (providerName.IndexOfAny(_illegalCharacters) != -1) { throw PSTraceSource.NewArgumentException( - "providerName", + nameof(providerName), SessionStateStrings.ProviderNameNotValid, providerName); } diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs index 5436dfb0bbb..121d2f1f872 100644 --- a/src/System.Management.Automation/namespaces/RegistryProvider.cs +++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs @@ -112,7 +112,7 @@ protected override PSDriveInfo NewDrive(PSDriveInfo drive) { if (drive == null) { - throw PSTraceSource.NewArgumentNullException("drive"); + throw PSTraceSource.NewArgumentNullException(nameof(drive)); } if (!ItemExists(drive.Root)) @@ -249,7 +249,7 @@ protected override void SetItem(string path, object value) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } // Confirm the set item with the user @@ -413,7 +413,7 @@ protected override void ClearItem(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } // Confirm the clear item with the user @@ -533,7 +533,7 @@ protected override void GetChildItems( if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (IsHiveContainer(path)) @@ -680,7 +680,7 @@ protected override void GetChildNames( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (path.Length == 0) @@ -871,12 +871,12 @@ protected override void RenameItem( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (string.IsNullOrEmpty(newName)) { - throw PSTraceSource.NewArgumentException("newName"); + throw PSTraceSource.NewArgumentException(nameof(newName)); } s_tracer.WriteLine("newName = {0}", newName); @@ -941,7 +941,7 @@ protected override void NewItem( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } // Confirm the new item with the user @@ -1100,7 +1100,7 @@ protected override void RemoveItem( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } s_tracer.WriteLine("recurse = {0}", recurse); @@ -1186,7 +1186,7 @@ protected override bool ItemExists(string path) if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } try @@ -1240,7 +1240,7 @@ protected override bool HasChildItems(string path) if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } try @@ -1298,12 +1298,12 @@ protected override void CopyItem( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (string.IsNullOrEmpty(destination)) { - throw PSTraceSource.NewArgumentException("destination"); + throw PSTraceSource.NewArgumentException(nameof(destination)); } s_tracer.WriteLine("destination = {0}", destination); @@ -1586,7 +1586,7 @@ protected override bool IsItemContainer(string path) { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } bool result = false; @@ -1642,12 +1642,12 @@ protected override void MoveItem( { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (string.IsNullOrEmpty(destination)) { - throw PSTraceSource.NewArgumentException("destination"); + throw PSTraceSource.NewArgumentException(nameof(destination)); } s_tracer.WriteLine("destination = {0}", destination); @@ -1785,7 +1785,7 @@ public void GetProperty( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (!CheckOperationNotAllowedOnHiveContainer(path)) @@ -1853,7 +1853,7 @@ public void SetProperty( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (!CheckOperationNotAllowedOnHiveContainer(path)) @@ -1863,7 +1863,7 @@ public void SetProperty( if (propertyValue == null) { - throw PSTraceSource.NewArgumentNullException("propertyValue"); + throw PSTraceSource.NewArgumentNullException(nameof(propertyValue)); } IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, true); @@ -1978,7 +1978,7 @@ public void ClearProperty( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (!CheckOperationNotAllowedOnHiveContainer(path)) @@ -2122,7 +2122,7 @@ public void NewProperty( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (!CheckOperationNotAllowedOnHiveContainer(path)) @@ -2234,7 +2234,7 @@ public void RemoveProperty( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (!CheckOperationNotAllowedOnHiveContainer(path)) @@ -2337,7 +2337,7 @@ public void RenameProperty( { if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (!CheckOperationNotAllowedOnHiveContainer(path)) @@ -2426,12 +2426,12 @@ public void CopyProperty( { if (sourcePath == null) { - throw PSTraceSource.NewArgumentNullException("sourcePath"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePath)); } if (destinationPath == null) { - throw PSTraceSource.NewArgumentNullException("destinationPath"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationPath)); } if (!CheckOperationNotAllowedOnHiveContainer(sourcePath, destinationPath)) @@ -2526,12 +2526,12 @@ public void MoveProperty( { if (sourcePath == null) { - throw PSTraceSource.NewArgumentNullException("sourcePath"); + throw PSTraceSource.NewArgumentNullException(nameof(sourcePath)); } if (destinationPath == null) { - throw PSTraceSource.NewArgumentNullException("destinationPath"); + throw PSTraceSource.NewArgumentNullException(nameof(destinationPath)); } if (!CheckOperationNotAllowedOnHiveContainer(sourcePath, destinationPath)) @@ -2979,7 +2979,7 @@ private void GetFilteredRegistryKeyProperties(string path, if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } filteredCollection = new Collection(); @@ -3199,7 +3199,7 @@ private bool IsHiveContainer(string path) bool result = false; if (path == null) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if (string.IsNullOrEmpty(path) || @@ -3273,7 +3273,7 @@ private IRegistryWrapper GetHiveRoot(string path) { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (TransactionAvailable()) @@ -3321,7 +3321,7 @@ private bool CreateIntermediateKeys(string path) // Check input. if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } try @@ -3359,7 +3359,7 @@ private bool CreateIntermediateKeys(string path) if (remainingPath.Length == 0 || rootKey == null) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } // Create new subkey..and close @@ -3373,7 +3373,7 @@ private bool CreateIntermediateKeys(string path) { // SubKey is null // Unable to create intermediate keys - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } result = true; @@ -3896,7 +3896,7 @@ private static RegistryValueKind GetValueKindFromObject(object value) { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } RegistryValueKind result = RegistryValueKind.Unknown; diff --git a/src/System.Management.Automation/namespaces/RegistrySecurity.cs b/src/System.Management.Automation/namespaces/RegistrySecurity.cs index cd05967b7eb..04f25d7f06f 100644 --- a/src/System.Management.Automation/namespaces/RegistrySecurity.cs +++ b/src/System.Management.Automation/namespaces/RegistrySecurity.cs @@ -48,12 +48,12 @@ public void GetSecurityDescriptor(string path, // Validate input first. if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentNullException("path"); + throw PSTraceSource.NewArgumentNullException(nameof(path)); } if ((sections & ~AccessControlSections.All) != 0) { - throw PSTraceSource.NewArgumentException("sections"); + throw PSTraceSource.NewArgumentException(nameof(sections)); } path = NormalizePath(path); @@ -93,12 +93,12 @@ public void SetSecurityDescriptor( if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (securityDescriptor == null) { - throw PSTraceSource.NewArgumentNullException("securityDescriptor"); + throw PSTraceSource.NewArgumentNullException(nameof(securityDescriptor)); } path = NormalizePath(path); @@ -110,7 +110,7 @@ public void SetSecurityDescriptor( if (sd == null) { - throw PSTraceSource.NewArgumentException("securityDescriptor"); + throw PSTraceSource.NewArgumentException(nameof(securityDescriptor)); } } else @@ -119,7 +119,7 @@ public void SetSecurityDescriptor( if (sd == null) { - throw PSTraceSource.NewArgumentException("securityDescriptor"); + throw PSTraceSource.NewArgumentException(nameof(securityDescriptor)); } } diff --git a/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs b/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs index f3720bb130d..33b043ce919 100644 --- a/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs +++ b/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs @@ -190,7 +190,7 @@ protected override void SetItem( if (string.IsNullOrEmpty(name)) { WriteError(new ErrorRecord( - PSTraceSource.NewArgumentNullException("name"), + PSTraceSource.NewArgumentNullException(nameof(name)), "SetItemNullName", ErrorCategory.InvalidArgument, name)); @@ -241,7 +241,7 @@ protected override void ClearItem(string path) if (string.IsNullOrEmpty(path)) { WriteError(new ErrorRecord( - PSTraceSource.NewArgumentNullException("path"), + PSTraceSource.NewArgumentNullException(nameof(path)), "ClearItemNullPath", ErrorCategory.InvalidArgument, path)); @@ -608,7 +608,7 @@ protected override void RemoveItem(string path, bool recurse) if (string.IsNullOrEmpty(path)) { Exception e = - PSTraceSource.NewArgumentException("path"); + PSTraceSource.NewArgumentException(nameof(path)); WriteError(new ErrorRecord( e, "RemoveItemNullPath", @@ -682,7 +682,7 @@ protected override void NewItem(string path, string type, object newItem) if (string.IsNullOrEmpty(path)) { Exception e = - PSTraceSource.NewArgumentException("path"); + PSTraceSource.NewArgumentException(nameof(path)); WriteError(new ErrorRecord( e, "NewItemNullPath", @@ -710,7 +710,7 @@ protected override void NewItem(string path, string type, object newItem) PSArgumentException e = (PSArgumentException) PSTraceSource.NewArgumentException( - "path", + nameof(path), SessionStateStrings.NewItemAlreadyExists, path); @@ -760,7 +760,7 @@ protected override void CopyItem(string path, string copyPath, bool recurse) if (string.IsNullOrEmpty(path)) { Exception e = - PSTraceSource.NewArgumentException("path"); + PSTraceSource.NewArgumentException(nameof(path)); WriteError(new ErrorRecord( e, "CopyItemNullPath", @@ -840,7 +840,7 @@ protected override void CopyItem(string path, string copyPath, bool recurse) PSArgumentException e = (PSArgumentException) PSTraceSource.NewArgumentException( - "path", + nameof(path), SessionStateStrings.CopyItemDoesntExist, path); @@ -866,7 +866,7 @@ protected override void RenameItem(string name, string newName) if (string.IsNullOrEmpty(name)) { Exception e = - PSTraceSource.NewArgumentException("name"); + PSTraceSource.NewArgumentException(nameof(name)); WriteError(new ErrorRecord( e, "RenameItemNullPath", @@ -899,7 +899,7 @@ protected override void RenameItem(string name, string newName) PSArgumentException e = (PSArgumentException) PSTraceSource.NewArgumentException( - "newName", + nameof(newName), SessionStateStrings.NewItemAlreadyExists, newName); @@ -986,7 +986,7 @@ protected override void RenameItem(string name, string newName) PSArgumentException e = (PSArgumentException) PSTraceSource.NewArgumentException( - "name", + nameof(name), SessionStateStrings.RenameItemDoesntExist, name); @@ -1104,12 +1104,12 @@ internal SessionStateProviderBaseContentReaderWriter(string path, SessionStatePr { if (string.IsNullOrEmpty(path)) { - throw PSTraceSource.NewArgumentException("path"); + throw PSTraceSource.NewArgumentException(nameof(path)); } if (provider == null) { - throw PSTraceSource.NewArgumentNullException("provider"); + throw PSTraceSource.NewArgumentNullException(nameof(provider)); } _path = path; @@ -1175,7 +1175,7 @@ public IList Write(IList content) { if (content == null) { - throw PSTraceSource.NewArgumentNullException("content"); + throw PSTraceSource.NewArgumentNullException(nameof(content)); } // Unravel the IList if there is only one value diff --git a/src/System.Management.Automation/namespaces/StackInfo.cs b/src/System.Management.Automation/namespaces/StackInfo.cs index 4715c28172a..887285c37fe 100644 --- a/src/System.Management.Automation/namespaces/StackInfo.cs +++ b/src/System.Management.Automation/namespaces/StackInfo.cs @@ -29,12 +29,12 @@ internal PathInfoStack(string stackName, Stack locationStack) : base() { if (locationStack == null) { - throw PSTraceSource.NewArgumentNullException("locationStack"); + throw PSTraceSource.NewArgumentNullException(nameof(locationStack)); } if (string.IsNullOrEmpty(stackName)) { - throw PSTraceSource.NewArgumentException("stackName"); + throw PSTraceSource.NewArgumentException(nameof(stackName)); } Name = stackName; diff --git a/src/System.Management.Automation/security/Authenticode.cs b/src/System.Management.Automation/security/Authenticode.cs index 49d0f79783e..cf5e559f830 100644 --- a/src/System.Management.Automation/security/Authenticode.cs +++ b/src/System.Management.Automation/security/Authenticode.cs @@ -112,7 +112,7 @@ internal static Signature SignFile(SigningOption option, (timeStampServerUrl.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0)) { throw PSTraceSource.NewArgumentException( - "certificate", + nameof(certificate), Authenticode.TimeStampUrlRequired); } } @@ -131,7 +131,7 @@ internal static Signature SignFile(SigningOption option, if (oidPtr == IntPtr.Zero) { throw PSTraceSource.NewArgumentException( - "certificate", + nameof(certificate), Authenticode.InvalidHashAlgorithm); } else @@ -146,7 +146,7 @@ internal static Signature SignFile(SigningOption option, if (!SecuritySupport.CertIsGoodForSigning(certificate)) { throw PSTraceSource.NewArgumentException( - "certificate", + nameof(certificate), Authenticode.CertNotGoodForSigning); } @@ -226,7 +226,7 @@ internal static Signature SignFile(SigningOption option, if (error == Win32Errors.NTE_BAD_ALGID) { throw PSTraceSource.NewArgumentException( - "certificate", + nameof(certificate), Authenticode.InvalidHashAlgorithm); } diff --git a/src/System.Management.Automation/security/CredentialParameter.cs b/src/System.Management.Automation/security/CredentialParameter.cs index 1472f331e49..0d48e4fa738 100644 --- a/src/System.Management.Automation/security/CredentialParameter.cs +++ b/src/System.Management.Automation/security/CredentialParameter.cs @@ -37,7 +37,7 @@ public override object Transform(EngineIntrinsics engineIntrinsics, object input (engineIntrinsics.Host == null) || (engineIntrinsics.Host.UI == null)) { - throw PSTraceSource.NewArgumentNullException("engineIntrinsics"); + throw PSTraceSource.NewArgumentNullException(nameof(engineIntrinsics)); } if (inputData == null) diff --git a/src/System.Management.Automation/security/SecureStringHelper.cs b/src/System.Management.Automation/security/SecureStringHelper.cs index bc2c3c6374c..63066cbd291 100644 --- a/src/System.Management.Automation/security/SecureStringHelper.cs +++ b/src/System.Management.Automation/security/SecureStringHelper.cs @@ -185,7 +185,7 @@ internal static SecureString Unprotect(string input) Utils.CheckArgForNullOrEmpty(input, "input"); if ((input.Length % 2) != 0) { - throw PSTraceSource.NewArgumentException("input", Serialization.InvalidEncryptedString, input); + throw PSTraceSource.NewArgumentException(nameof(input), Serialization.InvalidEncryptedString, input); } byte[] data = null; @@ -432,7 +432,7 @@ public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtec { if (userData == null) { - throw new ArgumentNullException("userData"); + throw new ArgumentNullException(nameof(userData)); } GCHandle pbDataIn = new GCHandle(); @@ -520,7 +520,7 @@ public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, Dat { if (encryptedData == null) { - throw new ArgumentNullException("encryptedData"); + throw new ArgumentNullException(nameof(encryptedData)); } GCHandle pbDataIn = new GCHandle(); diff --git a/src/System.Management.Automation/security/SecurityManager.cs b/src/System.Management.Automation/security/SecurityManager.cs index 7d6478601d7..a5140ea8b19 100644 --- a/src/System.Management.Automation/security/SecurityManager.cs +++ b/src/System.Management.Automation/security/SecurityManager.cs @@ -83,7 +83,7 @@ public PSAuthorizationManager(string shellId) { if (string.IsNullOrEmpty(shellId)) { - throw PSTraceSource.NewArgumentNullException("shellId"); + throw PSTraceSource.NewArgumentNullException(nameof(shellId)); } _shellId = shellId; diff --git a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs index b1f13ab0cf0..927bf963332 100644 --- a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs +++ b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs @@ -90,27 +90,27 @@ string vendorFallback { if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentNullException("name"); + throw PSTraceSource.NewArgumentNullException(nameof(name)); } if (string.IsNullOrEmpty(applicationBase)) { - throw PSTraceSource.NewArgumentNullException("applicationBase"); + throw PSTraceSource.NewArgumentNullException(nameof(applicationBase)); } if (string.IsNullOrEmpty(assemblyName)) { - throw PSTraceSource.NewArgumentNullException("assemblyName"); + throw PSTraceSource.NewArgumentNullException(nameof(assemblyName)); } if (string.IsNullOrEmpty(moduleName)) { - throw PSTraceSource.NewArgumentNullException("moduleName"); + throw PSTraceSource.NewArgumentNullException(nameof(moduleName)); } if (psVersion == null) { - throw PSTraceSource.NewArgumentNullException("psVersion"); + throw PSTraceSource.NewArgumentNullException(nameof(psVersion)); } if (version == null) @@ -578,7 +578,7 @@ internal static Collection ReadAll(string psVersion) { if (string.IsNullOrEmpty(psVersion)) { - throw PSTraceSource.NewArgumentNullException("psVersion"); + throw PSTraceSource.NewArgumentNullException(nameof(psVersion)); } RegistryKey monadRootKey = GetMonadRootKey(); @@ -655,12 +655,12 @@ internal static PSSnapInInfo Read(string psVersion, string mshsnapinId) { if (string.IsNullOrEmpty(psVersion)) { - throw PSTraceSource.NewArgumentNullException("psVersion"); + throw PSTraceSource.NewArgumentNullException(nameof(psVersion)); } if (string.IsNullOrEmpty(mshsnapinId)) { - throw PSTraceSource.NewArgumentNullException("mshsnapinId"); + throw PSTraceSource.NewArgumentNullException(nameof(mshsnapinId)); } // PSSnapIn Reader wont service invalid mshsnapins // Monad has specific restrictions on the mshsnapinid like @@ -698,7 +698,7 @@ private static PSSnapInInfo ReadOne(RegistryKey mshSnapInRoot, string mshsnapinI if (mshsnapinKey == null) { s_mshsnapinTracer.TraceError("Error opening registry key {0}\\{1}.", mshSnapInRoot.Name, mshsnapinId); - throw PSTraceSource.NewArgumentException("mshsnapinId", MshSnapinInfo.MshSnapinDoesNotExist, mshsnapinId); + throw PSTraceSource.NewArgumentException(nameof(mshsnapinId), MshSnapinInfo.MshSnapinDoesNotExist, mshsnapinId); } string applicationBase = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_ApplicationBase, true); @@ -759,7 +759,7 @@ private static Collection ReadMultiStringValue(RegistryKey mshsnapinKey, { s_mshsnapinTracer.TraceError("Mandatory property {0} not specified for registry key {1}", name, mshsnapinKey.Name); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.MandatoryValueNotPresent, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.MandatoryValueNotPresent, name, mshsnapinKey.Name); } else { @@ -787,7 +787,7 @@ private static Collection ReadMultiStringValue(RegistryKey mshsnapinKey, { s_mshsnapinTracer.TraceError("Cannot get string/multi-string value for mandatory property {0} in registry key {1}", name, mshsnapinKey.Name); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.MandatoryValueNotInCorrectFormatMultiString, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.MandatoryValueNotInCorrectFormatMultiString, name, mshsnapinKey.Name); } else { @@ -820,7 +820,7 @@ internal static string ReadStringValue(RegistryKey mshsnapinKey, string name, bo { s_mshsnapinTracer.TraceError("Mandatory property {0} not specified for registry key {1}", name, mshsnapinKey.Name); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.MandatoryValueNotPresent, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.MandatoryValueNotPresent, name, mshsnapinKey.Name); } string s = value as string; @@ -828,7 +828,7 @@ internal static string ReadStringValue(RegistryKey mshsnapinKey, string name, bo { s_mshsnapinTracer.TraceError("Value is null or empty for mandatory property {0} in {1}", name, mshsnapinKey.Name); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.MandatoryValueNotInCorrectFormat, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.MandatoryValueNotInCorrectFormat, name, mshsnapinKey.Name); } s_mshsnapinTracer.WriteLine("Successfully read value {0} for property {1} from {2}", @@ -855,22 +855,22 @@ internal static Version ReadVersionValue(RegistryKey mshsnapinKey, string name, catch (ArgumentOutOfRangeException) { s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); } catch (ArgumentException) { s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); } catch (OverflowException) { s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); } catch (FormatException) { s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp); - throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); + throw PSTraceSource.NewArgumentException(nameof(name), MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name); } s_mshsnapinTracer.WriteLine("Successfully converted string {0} to version format.", v); @@ -1192,7 +1192,7 @@ internal static RegistryKey versionRoot = rootKey.OpenSubKey(versionKey); if (versionRoot == null) { - throw PSTraceSource.NewArgumentException("psVersion", MshSnapinInfo.SpecifiedVersionNotFound, versionKey); + throw PSTraceSource.NewArgumentException(nameof(psVersion), MshSnapinInfo.SpecifiedVersionNotFound, versionKey); } return versionRoot; @@ -1219,7 +1219,7 @@ private static RegistryKey mshsnapinRoot = versionRootKey.OpenSubKey(RegistryStrings.MshSnapinKey); if (mshsnapinRoot == null) { - throw PSTraceSource.NewArgumentException("psVersion", MshSnapinInfo.NoMshSnapinPresentForVersion, psVersion); + throw PSTraceSource.NewArgumentException(nameof(psVersion), MshSnapinInfo.NoMshSnapinPresentForVersion, psVersion); } return mshsnapinRoot; @@ -1246,7 +1246,7 @@ internal static RegistryKey mshsnapinRoot = versionRootKey.OpenSubKey(RegistryStrings.MshSnapinKey); if (mshsnapinRoot == null) { - throw PSTraceSource.NewArgumentException("psVersion", MshSnapinInfo.NoMshSnapinPresentForVersion, psVersion); + throw PSTraceSource.NewArgumentException(nameof(psVersion), MshSnapinInfo.NoMshSnapinPresentForVersion, psVersion); } RegistryKey mshsnapinKey = mshsnapinRoot.OpenSubKey(mshSnapInName); diff --git a/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs b/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs index 130ebbe8241..9ee9588be65 100644 --- a/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs +++ b/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs @@ -192,7 +192,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw PSTraceSource.NewArgumentNullException("info"); + throw PSTraceSource.NewArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs b/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs index ea6ecd3b0ba..2dc15062394 100644 --- a/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs +++ b/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs @@ -87,7 +87,7 @@ protected CommandNotFoundException(SerializationInfo info, { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } _commandName = info.GetString("CommandName"); @@ -107,7 +107,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -394,7 +394,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -470,7 +470,7 @@ private static string BuildMessage( StringBuilder sb = new StringBuilder(); if (missingItems == null) { - throw PSTraceSource.NewArgumentNullException("missingItems"); + throw PSTraceSource.NewArgumentNullException(nameof(missingItems)); } foreach (string missingItem in missingItems) diff --git a/src/System.Management.Automation/utils/ExecutionExceptions.cs b/src/System.Management.Automation/utils/ExecutionExceptions.cs index ab60cc636ba..2b7fcd7cff4 100644 --- a/src/System.Management.Automation/utils/ExecutionExceptions.cs +++ b/src/System.Management.Automation/utils/ExecutionExceptions.cs @@ -33,7 +33,7 @@ internal CmdletInvocationException(ErrorRecord errorRecord) { if (errorRecord == null) { - throw new ArgumentNullException("errorRecord"); + throw new ArgumentNullException(nameof(errorRecord)); } _errorRecord = errorRecord; @@ -58,7 +58,7 @@ internal CmdletInvocationException(Exception innerException, { if (innerException == null) { - throw new ArgumentNullException("innerException"); + throw new ArgumentNullException(nameof(innerException)); } // invocationInfo may be null @@ -142,7 +142,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -208,7 +208,7 @@ internal CmdletProviderInvocationException( { if (innerException == null) { - throw new ArgumentNullException("innerException"); + throw new ArgumentNullException(nameof(innerException)); } _providerInvocationException = innerException; @@ -473,7 +473,7 @@ internal ActionPreferenceStopException(ErrorRecord error) { if (error == null) { - throw new ArgumentNullException("error"); + throw new ArgumentNullException(nameof(error)); } _errorRecord = error; @@ -501,7 +501,7 @@ internal ActionPreferenceStopException(InvocationInfo invocationInfo, { if (errorRecord == null) { - throw new ArgumentNullException("errorRecord"); + throw new ArgumentNullException(nameof(errorRecord)); } _errorRecord = errorRecord; @@ -725,7 +725,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshArgumentException.cs b/src/System.Management.Automation/utils/MshArgumentException.cs index e937a275b4d..26980059c00 100644 --- a/src/System.Management.Automation/utils/MshArgumentException.cs +++ b/src/System.Management.Automation/utils/MshArgumentException.cs @@ -88,7 +88,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshArgumentNullException.cs b/src/System.Management.Automation/utils/MshArgumentNullException.cs index a7b870bcab0..03ab45654a3 100644 --- a/src/System.Management.Automation/utils/MshArgumentNullException.cs +++ b/src/System.Management.Automation/utils/MshArgumentNullException.cs @@ -99,7 +99,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshArgumentOutOfRangeException.cs b/src/System.Management.Automation/utils/MshArgumentOutOfRangeException.cs index e54320235a2..a6bb0dfd3ff 100644 --- a/src/System.Management.Automation/utils/MshArgumentOutOfRangeException.cs +++ b/src/System.Management.Automation/utils/MshArgumentOutOfRangeException.cs @@ -86,7 +86,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshInvalidOperationException.cs b/src/System.Management.Automation/utils/MshInvalidOperationException.cs index e4c0b7b111e..75d7094432e 100644 --- a/src/System.Management.Automation/utils/MshInvalidOperationException.cs +++ b/src/System.Management.Automation/utils/MshInvalidOperationException.cs @@ -57,7 +57,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshNotImplementedException.cs b/src/System.Management.Automation/utils/MshNotImplementedException.cs index c84f66e1ac4..e6a1128a38d 100644 --- a/src/System.Management.Automation/utils/MshNotImplementedException.cs +++ b/src/System.Management.Automation/utils/MshNotImplementedException.cs @@ -57,7 +57,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshNotSupportedException.cs b/src/System.Management.Automation/utils/MshNotSupportedException.cs index fc4ce6871f3..e6847ba6d16 100644 --- a/src/System.Management.Automation/utils/MshNotSupportedException.cs +++ b/src/System.Management.Automation/utils/MshNotSupportedException.cs @@ -57,7 +57,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshObjectDisposedException.cs b/src/System.Management.Automation/utils/MshObjectDisposedException.cs index 0de12d3b0d3..93cf76100bb 100644 --- a/src/System.Management.Automation/utils/MshObjectDisposedException.cs +++ b/src/System.Management.Automation/utils/MshObjectDisposedException.cs @@ -85,7 +85,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/MshTraceSource.cs b/src/System.Management.Automation/utils/MshTraceSource.cs index 9a4d28b8b5b..9bb0cfbcc3d 100644 --- a/src/System.Management.Automation/utils/MshTraceSource.cs +++ b/src/System.Management.Automation/utils/MshTraceSource.cs @@ -103,7 +103,7 @@ internal static PSTraceSource GetTracer( // 2005/04/13-JonN In theory this should be ArgumentException, // but I don't want to deal with loading the string in this // low-level code. - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } lock (PSTraceSource.s_getTracerLock) @@ -230,7 +230,7 @@ internal static PSArgumentNullException NewArgumentNullException(string paramNam { if (string.IsNullOrEmpty(paramName)) { - throw new ArgumentNullException("paramName"); + throw new ArgumentNullException(nameof(paramName)); } string message = StringUtil.Format(AutomationExceptions.ArgumentNull, paramName); @@ -259,12 +259,12 @@ internal static PSArgumentNullException NewArgumentNullException( { if (string.IsNullOrEmpty(paramName)) { - throw NewArgumentNullException("paramName"); + throw NewArgumentNullException(nameof(paramName)); } if (string.IsNullOrEmpty(resourceString)) { - throw NewArgumentNullException("resourceString"); + throw NewArgumentNullException(nameof(resourceString)); } string message = StringUtil.Format(resourceString, args); @@ -289,7 +289,7 @@ internal static PSArgumentException NewArgumentException(string paramName) { if (string.IsNullOrEmpty(paramName)) { - throw new ArgumentNullException("paramName"); + throw new ArgumentNullException(nameof(paramName)); } string message = StringUtil.Format(AutomationExceptions.Argument, paramName); @@ -319,12 +319,12 @@ internal static PSArgumentException NewArgumentException( { if (string.IsNullOrEmpty(paramName)) { - throw NewArgumentNullException("paramName"); + throw NewArgumentNullException(nameof(paramName)); } if (string.IsNullOrEmpty(resourceString)) { - throw NewArgumentNullException("resourceString"); + throw NewArgumentNullException(nameof(resourceString)); } string message = StringUtil.Format(resourceString, args); @@ -366,7 +366,7 @@ internal static PSInvalidOperationException NewInvalidOperationException( { if (string.IsNullOrEmpty(resourceString)) { - throw NewArgumentNullException("resourceString"); + throw NewArgumentNullException(nameof(resourceString)); } string message = StringUtil.Format(resourceString, args); @@ -396,7 +396,7 @@ internal static PSInvalidOperationException NewInvalidOperationException( { if (string.IsNullOrEmpty(resourceString)) { - throw NewArgumentNullException("resourceString"); + throw NewArgumentNullException(nameof(resourceString)); } string message = StringUtil.Format(resourceString, args); @@ -438,7 +438,7 @@ internal static PSNotSupportedException NewNotSupportedException( { if (string.IsNullOrEmpty(resourceString)) { - throw NewArgumentNullException("resourceString"); + throw NewArgumentNullException(nameof(resourceString)); } string message = StringUtil.Format(resourceString, args); @@ -479,7 +479,7 @@ internal static PSArgumentOutOfRangeException NewArgumentOutOfRangeException(str { if (string.IsNullOrEmpty(paramName)) { - throw new ArgumentNullException("paramName"); + throw new ArgumentNullException(nameof(paramName)); } string message = StringUtil.Format(AutomationExceptions.ArgumentOutOfRange, paramName); @@ -511,12 +511,12 @@ internal static PSArgumentOutOfRangeException NewArgumentOutOfRangeException( { if (string.IsNullOrEmpty(paramName)) { - throw NewArgumentNullException("paramName"); + throw NewArgumentNullException(nameof(paramName)); } if (string.IsNullOrEmpty(resourceString)) { - throw NewArgumentNullException("resourceString"); + throw NewArgumentNullException(nameof(resourceString)); } string message = StringUtil.Format(resourceString, args); @@ -542,7 +542,7 @@ internal static PSObjectDisposedException NewObjectDisposedException(string obje { if (string.IsNullOrEmpty(objectName)) { - throw NewArgumentNullException("objectName"); + throw NewArgumentNullException(nameof(objectName)); } string message = StringUtil.Format(AutomationExceptions.ObjectDisposed, objectName); diff --git a/src/System.Management.Automation/utils/ObjectReader.cs b/src/System.Management.Automation/utils/ObjectReader.cs index 99cf452fb38..5f9a57eec18 100644 --- a/src/System.Management.Automation/utils/ObjectReader.cs +++ b/src/System.Management.Automation/utils/ObjectReader.cs @@ -27,7 +27,7 @@ public ObjectReaderBase([In, Out] ObjectStreamBase stream) { if (stream == null) { - throw new ArgumentNullException("stream", "stream may not be null"); + throw new ArgumentNullException(nameof(stream), "stream may not be null"); } _stream = stream; @@ -573,7 +573,7 @@ public override Collection NonBlockingRead(int maxRequested) { if (maxRequested < 0) { - throw PSTraceSource.NewArgumentOutOfRangeException("maxRequested", maxRequested); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(maxRequested), maxRequested); } if (maxRequested == 0) @@ -755,7 +755,7 @@ public override Collection NonBlockingRead(int maxRequested) { if (maxRequested < 0) { - throw PSTraceSource.NewArgumentOutOfRangeException("maxRequested", maxRequested); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(maxRequested), maxRequested); } if (maxRequested == 0) diff --git a/src/System.Management.Automation/utils/ObjectStream.cs b/src/System.Management.Automation/utils/ObjectStream.cs index 607d6acc94a..eccfdfad901 100644 --- a/src/System.Management.Automation/utils/ObjectStream.cs +++ b/src/System.Management.Automation/utils/ObjectStream.cs @@ -541,7 +541,7 @@ internal ObjectStream(int capacity) { if (capacity <= 0 || capacity > Int32.MaxValue) { - throw PSTraceSource.NewArgumentOutOfRangeException("capacity", capacity); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(capacity), capacity); } // the maximum number of objects to allow in the stream at a given time. @@ -1124,7 +1124,7 @@ internal override Collection Read(int count) { if (count < 0) { - throw PSTraceSource.NewArgumentOutOfRangeException("count", count); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(count), count); } if (count == 0) @@ -1232,7 +1232,7 @@ internal override Collection NonBlockingRead(int maxRequested) if (maxRequested < 0) { - throw PSTraceSource.NewArgumentOutOfRangeException("maxRequested", maxRequested); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(maxRequested), maxRequested); } try @@ -1583,7 +1583,7 @@ internal PSDataCollectionStream(Guid psInstanceId, PSDataCollection storeToUs { if (storeToUse == null) { - throw PSTraceSource.NewArgumentNullException("storeToUse"); + throw PSTraceSource.NewArgumentNullException(nameof(storeToUse)); } _objects = storeToUse; diff --git a/src/System.Management.Automation/utils/ObjectWriter.cs b/src/System.Management.Automation/utils/ObjectWriter.cs index 9da4a2307a3..d4fe3493b78 100644 --- a/src/System.Management.Automation/utils/ObjectWriter.cs +++ b/src/System.Management.Automation/utils/ObjectWriter.cs @@ -25,7 +25,7 @@ public ObjectWriter([In, Out] ObjectStreamBase stream) { if (stream == null) { - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); } _stream = stream; diff --git a/src/System.Management.Automation/utils/ParameterBinderExceptions.cs b/src/System.Management.Automation/utils/ParameterBinderExceptions.cs index 4daa7dc5962..df08765bb2f 100644 --- a/src/System.Management.Automation/utils/ParameterBinderExceptions.cs +++ b/src/System.Management.Automation/utils/ParameterBinderExceptions.cs @@ -86,12 +86,12 @@ internal ParameterBindingException( { if (string.IsNullOrEmpty(resourceString)) { - throw PSTraceSource.NewArgumentException("resourceString"); + throw PSTraceSource.NewArgumentException(nameof(resourceString)); } if (string.IsNullOrEmpty(errorId)) { - throw PSTraceSource.NewArgumentException("errorId"); + throw PSTraceSource.NewArgumentException(nameof(errorId)); } _invocationInfo = invocationInfo; @@ -194,17 +194,17 @@ internal ParameterBindingException( { if (invocationInfo == null) { - throw PSTraceSource.NewArgumentNullException("invocationInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(invocationInfo)); } if (string.IsNullOrEmpty(resourceString)) { - throw PSTraceSource.NewArgumentException("resourceString"); + throw PSTraceSource.NewArgumentException(nameof(resourceString)); } if (string.IsNullOrEmpty(errorId)) { - throw PSTraceSource.NewArgumentException("errorId"); + throw PSTraceSource.NewArgumentException(nameof(errorId)); } _invocationInfo = invocationInfo; @@ -248,12 +248,12 @@ internal ParameterBindingException( { if (pbex == null) { - throw PSTraceSource.NewArgumentNullException("pbex"); + throw PSTraceSource.NewArgumentNullException(nameof(pbex)); } if (string.IsNullOrEmpty(resourceString)) { - throw PSTraceSource.NewArgumentException("resourceString"); + throw PSTraceSource.NewArgumentException(nameof(resourceString)); } _invocationInfo = pbex.CommandInvocation; @@ -327,7 +327,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/ParserException.cs b/src/System.Management.Automation/utils/ParserException.cs index ac10c577481..098617d0fdd 100644 --- a/src/System.Management.Automation/utils/ParserException.cs +++ b/src/System.Management.Automation/utils/ParserException.cs @@ -47,7 +47,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -132,7 +132,7 @@ public ParseException(Language.ParseError[] errors) { if ((errors == null) || (errors.Length == 0)) { - throw new ArgumentNullException("errors"); + throw new ArgumentNullException(nameof(errors)); } _errors = errors; diff --git a/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs b/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs index 0f35f718faa..d6d845c7281 100644 --- a/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs +++ b/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs @@ -18,7 +18,7 @@ internal PowerShellExecutionHelper(PowerShell powershell) { if (powershell == null) { - throw PSTraceSource.NewArgumentNullException("powershell"); + throw PSTraceSource.NewArgumentNullException(nameof(powershell)); } CurrentPowerShell = powershell; diff --git a/src/System.Management.Automation/utils/PsUtils.cs b/src/System.Management.Automation/utils/PsUtils.cs index 0d8c3473ba0..b27f6f7e149 100644 --- a/src/System.Management.Automation/utils/PsUtils.cs +++ b/src/System.Management.Automation/utils/PsUtils.cs @@ -298,11 +298,11 @@ internal static Hashtable EvaluatePowerShellDataFile( bool allowEnvironmentVariables, bool skipPathValidation) { - if (!skipPathValidation && string.IsNullOrEmpty(parameterName)) { throw PSTraceSource.NewArgumentNullException("parameterName"); } + if (!skipPathValidation && string.IsNullOrEmpty(parameterName)) { throw PSTraceSource.NewArgumentNullException(nameof(parameterName)); } - if (string.IsNullOrEmpty(psDataFilePath)) { throw PSTraceSource.NewArgumentNullException("psDataFilePath"); } + if (string.IsNullOrEmpty(psDataFilePath)) { throw PSTraceSource.NewArgumentNullException(nameof(psDataFilePath)); } - if (context == null) { throw PSTraceSource.NewArgumentNullException("context"); } + if (context == null) { throw PSTraceSource.NewArgumentNullException(nameof(context)); } string resolvedPath; if (skipPathValidation) @@ -486,7 +486,7 @@ internal static string StringToBase64String(string input) // shell crashes if you pass an empty script block to a native command if (input == null) { - throw PSTraceSource.NewArgumentNullException("input"); + throw PSTraceSource.NewArgumentNullException(nameof(input)); } string base64 = Convert.ToBase64String @@ -505,7 +505,7 @@ internal static string Base64ToString(string base64) { if (string.IsNullOrEmpty(base64)) { - throw PSTraceSource.NewArgumentNullException("base64"); + throw PSTraceSource.NewArgumentNullException(nameof(base64)); } string output = new string(Encoding.Unicode.GetChars(Convert.FromBase64String(base64))); @@ -521,7 +521,7 @@ internal static object[] Base64ToArgsConverter(string base64) { if (string.IsNullOrEmpty(base64)) { - throw PSTraceSource.NewArgumentNullException("base64"); + throw PSTraceSource.NewArgumentNullException(nameof(base64)); } string decoded = new string(Encoding.Unicode.GetChars(Convert.FromBase64String(base64))); diff --git a/src/System.Management.Automation/utils/ResourceManagerCache.cs b/src/System.Management.Automation/utils/ResourceManagerCache.cs index 7c7036e5f09..c1e463f5ad9 100644 --- a/src/System.Management.Automation/utils/ResourceManagerCache.cs +++ b/src/System.Management.Automation/utils/ResourceManagerCache.cs @@ -43,12 +43,12 @@ internal static ResourceManager GetResourceManager( { if (assembly == null) { - throw PSTraceSource.NewArgumentNullException("assembly"); + throw PSTraceSource.NewArgumentNullException(nameof(assembly)); } if (string.IsNullOrEmpty(baseName)) { - throw PSTraceSource.NewArgumentException("baseName"); + throw PSTraceSource.NewArgumentException(nameof(baseName)); } // Check to see if the manager is already in the cache @@ -153,17 +153,17 @@ internal static string GetResourceString( { if (assembly == null) { - throw PSTraceSource.NewArgumentNullException("assembly"); + throw PSTraceSource.NewArgumentNullException(nameof(assembly)); } if (string.IsNullOrEmpty(baseName)) { - throw PSTraceSource.NewArgumentException("baseName"); + throw PSTraceSource.NewArgumentException(nameof(baseName)); } if (string.IsNullOrEmpty(resourceId)) { - throw PSTraceSource.NewArgumentException("resourceId"); + throw PSTraceSource.NewArgumentException(nameof(resourceId)); } ResourceManager resourceManager = null; @@ -234,7 +234,7 @@ private static ResourceManager InitRMWithAssembly(string baseName, Assembly asse { // 2004/10/11-JonN Do we need a better error message? I don't think so, // since this is private. - throw PSTraceSource.NewArgumentException("assemblyToUse"); + throw PSTraceSource.NewArgumentException(nameof(assemblyToUse)); } return rm; diff --git a/src/System.Management.Automation/utils/RuntimeException.cs b/src/System.Management.Automation/utils/RuntimeException.cs index 17ceb5d0068..3b9d6ae3d73 100644 --- a/src/System.Management.Automation/utils/RuntimeException.cs +++ b/src/System.Management.Automation/utils/RuntimeException.cs @@ -60,7 +60,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/SessionStateExceptions.cs b/src/System.Management.Automation/utils/SessionStateExceptions.cs index bb2532347f7..acf3d9b8306 100644 --- a/src/System.Management.Automation/utils/SessionStateExceptions.cs +++ b/src/System.Management.Automation/utils/SessionStateExceptions.cs @@ -98,7 +98,7 @@ internal ProviderInvocationException(ProviderInfo provider, ErrorRecord errorRec { if (errorRecord == null) { - throw new ArgumentNullException("errorRecord"); + throw new ArgumentNullException(nameof(errorRecord)); } _message = base.Message; @@ -482,7 +482,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont { if (info == null) { - throw new PSArgumentNullException("info"); + throw new PSArgumentNullException(nameof(info)); } base.GetObjectData(info, context); diff --git a/src/System.Management.Automation/utils/StructuredTraceSource.cs b/src/System.Management.Automation/utils/StructuredTraceSource.cs index 1aebf9534e4..c464a27cbaa 100644 --- a/src/System.Management.Automation/utils/StructuredTraceSource.cs +++ b/src/System.Management.Automation/utils/StructuredTraceSource.cs @@ -274,7 +274,7 @@ internal PSTraceSource(string fullName, string name, string description, bool tr // 2005/04/13-JonN In theory this should be ArgumentException, // but I don't want to deal with loading the string in this // low-level code. - throw new ArgumentNullException("fullName"); + throw new ArgumentNullException(nameof(fullName)); } try diff --git a/src/System.Management.Automation/utils/tracing/EtwActivity.cs b/src/System.Management.Automation/utils/tracing/EtwActivity.cs index 7dfac67ddb2..2bd8a57fbeb 100644 --- a/src/System.Management.Automation/utils/tracing/EtwActivity.cs +++ b/src/System.Management.Automation/utils/tracing/EtwActivity.cs @@ -122,12 +122,12 @@ public CorrelatedCallback(EtwActivity tracer, CallbackNoParameter callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } if (tracer == null) { - throw new ArgumentNullException("tracer"); + throw new ArgumentNullException(nameof(tracer)); } this.tracer = tracer; @@ -144,12 +144,12 @@ public CorrelatedCallback(EtwActivity tracer, CallbackWithState callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } if (tracer == null) { - throw new ArgumentNullException("tracer"); + throw new ArgumentNullException(nameof(tracer)); } this.tracer = tracer; @@ -166,12 +166,12 @@ public CorrelatedCallback(EtwActivity tracer, AsyncCallback callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } if (tracer == null) { - throw new ArgumentNullException("tracer"); + throw new ArgumentNullException(nameof(tracer)); } this.tracer = tracer; @@ -193,12 +193,12 @@ public CorrelatedCallback(EtwActivity tracer, CallbackWithStateAndArgs callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } if (tracer == null) { - throw new ArgumentNullException("tracer"); + throw new ArgumentNullException(nameof(tracer)); } this.tracer = tracer; @@ -380,7 +380,7 @@ public CallbackNoParameter Correlate(CallbackNoParameter callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } return new CorrelatedCallback(this, callback).Callback; @@ -395,7 +395,7 @@ public CallbackWithState Correlate(CallbackWithState callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } return new CorrelatedCallback(this, callback).Callback; @@ -410,7 +410,7 @@ public AsyncCallback Correlate(AsyncCallback callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } return new CorrelatedCallback(this, callback).Callback; @@ -426,7 +426,7 @@ public CallbackWithStateAndArgs Correlate(CallbackWithStateAndArgs callback) { if (callback == null) { - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); } return new CorrelatedCallback(this, callback).Callback; diff --git a/src/System.Management.Automation/utils/tracing/EtwActivityReverterMethodInvoker.cs b/src/System.Management.Automation/utils/tracing/EtwActivityReverterMethodInvoker.cs index 50bb00dd488..db63b2727d3 100644 --- a/src/System.Management.Automation/utils/tracing/EtwActivityReverterMethodInvoker.cs +++ b/src/System.Management.Automation/utils/tracing/EtwActivityReverterMethodInvoker.cs @@ -22,7 +22,7 @@ public EtwActivityReverterMethodInvoker(IEtwEventCorrelator eventCorrelator) { if (eventCorrelator == null) { - throw new ArgumentNullException("eventCorrelator"); + throw new ArgumentNullException(nameof(eventCorrelator)); } _eventCorrelator = eventCorrelator; diff --git a/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs b/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs index 32b0bb5a222..7e4e81abe06 100644 --- a/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs +++ b/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs @@ -63,7 +63,7 @@ public EtwEventCorrelator(EventProvider transferProvider, EventDescriptor transf { if (transferProvider == null) { - throw new ArgumentNullException("transferProvider"); + throw new ArgumentNullException(nameof(transferProvider)); } _transferProvider = transferProvider;