Use nameof operator (#12716)

# PR Summary

Using *Roslynator Command Line Tool version 0.1.0.4*

* Fix RCS1015:
  * `"argument"` → `nameof(argument)`
  * `enum.ToString()` → `nameof(enum)`

[RCS1015.log](https://github.com/PowerShell/PowerShell/files/4646102/RCS1015.log)


## PR Context

<!-- Provide a little reasoning as to why this Pull Request helps and why you have opened it. -->

## PR Checklist

- [x] [PR has a meaningful title](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
    - Use the present tense and imperative mood when describing your changes
- [x] [Summarized changes](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
- [x] [Make sure all `.h`, `.cpp`, `.cs`, `.ps1` and `.psm1` files have the correct copyright header](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
- [x] This PR is ready to merge and is not [Work in Progress](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---work-in-progress).
    - If the PR is work in progress, please add the prefix `WIP:` or `[ WIP ]` to the beginning of the title (the `WIP` bot will keep its status check at `Pending` while the prefix is present) and remove the prefix when the PR is ready.
- **[Breaking changes](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#making-breaking-changes)**
    - [x] None
    - **OR**
    - [ ] [Experimental feature(s) needed](https://github.com/MicrosoftDocs/PowerShell-Docs/blob/staging/reference/6/Microsoft.PowerShell.Core/About/about_Experimental_Features.md)
        - [ ] Experimental feature name(s): <!-- Experimental feature name(s) here -->
- **User-facing changes**
    - [x] Not Applicable
    - **OR**
    - [ ] [Documentation needed](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
        - [ ] Issue filed: <!-- Number/link of that issue here -->
- **Testing - New and feature**
    - [x] N/A or can only be tested interactively
    - **OR**
    - [ ] [Make sure you've added a new test if existing tests do not effectively test the code changed](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#before-submitting)
- **Tooling**
    - [x] I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.
    - **OR**
    - [ ] I have considered the user experience from a tooling perspective and enumerated concerns in the summary. This may include:
        - Impact on [PowerShell Editor Services](https://github.com/PowerShell/PowerShellEditorServices) which is used in the [PowerShell extension](https://github.com/PowerShell/vscode-powershell) for VSCode (which runs in a different PS Host).
        - Impact on Completions (both in the console and in editors) - one of PowerShell's most powerful features.
        - Impact on [PSScriptAnalyzer](https://github.com/PowerShell/PSScriptAnalyzer) (which provides linting & formatting in the editor extensions).
        - Impact on [EditorSyntax](https://github.com/PowerShell/EditorSyntax) (which provides syntax highlighting with in VSCode, GitHub, and many other editors).
This commit is contained in:
xtqqczze 2020-05-19 19:57:52 +01:00 committed by GitHub
parent 310ffe0b95
commit 9212aac0fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
278 changed files with 1429 additions and 1429 deletions

View file

@ -581,8 +581,8 @@ namespace Microsoft.PowerShell.Cmdletization
/// <param name="passThru"><c>true</c> if successful method invocations should emit downstream the <paramref name="objectInstance"/> being operated on.</param>
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 @@ namespace Microsoft.PowerShell.Cmdletization
/// <param name="methodInvocationInfo">Method invocation details.</param>
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))
{

View file

@ -56,7 +56,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
{
if (info == null)
{
throw new ArgumentNullException("info");
throw new ArgumentNullException(nameof(info));
}
_errorRecord = (ErrorRecord)info.GetValue("errorRecord", typeof(ErrorRecord));
@ -71,7 +71,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
{
if (info == null)
{
throw new ArgumentNullException("info");
throw new ArgumentNullException(nameof(info));
}
base.GetObjectData(info, context);

View file

@ -52,12 +52,12 @@ namespace Microsoft.PowerShell.Cim
{
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 @@ namespace Microsoft.PowerShell.Cim
/// <exception cref="PSInvalidCastException">The only kind of exception this method can throw.</exception>
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)
{

View file

@ -316,12 +316,12 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
{
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;

View file

@ -175,7 +175,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
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);

View file

@ -80,7 +80,7 @@ namespace Microsoft.PowerShell.Commands
internal static T GetFirst<T>(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 @@ namespace Microsoft.PowerShell.Commands
internal static T[] GetAll<T>(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<T>();

View file

@ -107,7 +107,7 @@ namespace Microsoft.PowerShell.Commands
{
if (info == null)
{
throw new PSArgumentNullException("info");
throw new PSArgumentNullException(nameof(info));
}
ComputerName = info.GetString("ComputerName");
@ -128,7 +128,7 @@ namespace Microsoft.PowerShell.Commands
{
if (info == null)
{
throw new PSArgumentNullException("info");
throw new PSArgumentNullException(nameof(info));
}
base.GetObjectData(info, context);

View file

@ -348,7 +348,7 @@ namespace Microsoft.PowerShell.Commands
{
if (pathInfo == null)
{
throw PSTraceSource.NewArgumentNullException("pathInfo");
throw PSTraceSource.NewArgumentNullException(nameof(pathInfo));
}
PathInfo = pathInfo;
@ -370,7 +370,7 @@ namespace Microsoft.PowerShell.Commands
{
if (contentHolders == null)
{
throw PSTraceSource.NewArgumentNullException("contentHolders");
throw PSTraceSource.NewArgumentNullException(nameof(contentHolders));
}
foreach (ContentHolder holder in contentHolders)

View file

@ -3005,7 +3005,7 @@ namespace Microsoft.PowerShell.Commands
base.GetObjectData(info, context);
if (info == null)
throw new ArgumentNullException("info");
throw new ArgumentNullException(nameof(info));
info.AddValue("ProcessName", _processName);
}

View file

@ -547,7 +547,7 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
{
if (info == null)
{
throw new ArgumentNullException("info");
throw new ArgumentNullException(nameof(info));
}
_serviceName = info.GetString("ServiceName");
@ -2581,7 +2581,7 @@ namespace Microsoft.PowerShell.Commands
{
if (info == null)
{
throw new ArgumentNullException("info");
throw new ArgumentNullException(nameof(info));
}
base.GetObjectData(info, context);

View file

@ -28,7 +28,7 @@ namespace Microsoft.PowerShell.Commands
{
if (paths == null || paths.Length == 0)
{
throw PSTraceSource.NewArgumentNullException("paths");
throw PSTraceSource.NewArgumentNullException(nameof(paths));
}
CmdletProviderContext context = new CmdletProviderContext(GetCurrentContext());

View file

@ -887,7 +887,7 @@ namespace Microsoft.PowerShell.Commands
case OutputAssemblyType.WindowsApplication:
return OutputKind.WindowsApplication;
default:
throw new ArgumentOutOfRangeException("outputType");
throw new ArgumentOutOfRangeException(nameof(outputType));
}
}

View file

@ -55,12 +55,12 @@ namespace System.Management.Automation
{
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;

View file

@ -75,7 +75,7 @@ namespace Microsoft.PowerShell.Commands
/// <param name="runspaceId">Runspace local Id.</param>
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;

View file

@ -59,17 +59,17 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
if (livePSObject == null)
{
throw new ArgumentNullException("livePSObject");
throw new ArgumentNullException(nameof(livePSObject));
}
if (_headerInfo == null)
@ -204,7 +204,7 @@ namespace Microsoft.PowerShell.Commands
{
if (livePSObject == null)
{
throw new ArgumentNullException("livePSObject");
throw new ArgumentNullException(nameof(livePSObject));
}
if (_headerInfo == null)

View file

@ -644,7 +644,7 @@ namespace Microsoft.PowerShell.Commands
{
if (maxValue < 0)
{
throw new ArgumentOutOfRangeException("maxValue", GetRandomCommandStrings.MaxMustBeGreaterThanZeroApi);
throw new ArgumentOutOfRangeException(nameof(maxValue), GetRandomCommandStrings.MaxMustBeGreaterThanZeroApi);
}
return Next(0, maxValue);
@ -660,7 +660,7 @@ namespace Microsoft.PowerShell.Commands
{
if (minValue > maxValue)
{
throw new ArgumentOutOfRangeException("minValue", GetRandomCommandStrings.MinGreaterThanOrEqualMaxApi);
throw new ArgumentOutOfRangeException(nameof(minValue), GetRandomCommandStrings.MinGreaterThanOrEqualMaxApi);
}
int randomNumber = 0;

View file

@ -187,7 +187,7 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(errorId))
{
throw PSTraceSource.NewArgumentNullException("errorId");
throw PSTraceSource.NewArgumentNullException(nameof(errorId));
}
return new ErrorDetails(
@ -564,7 +564,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(commandName))
{
throw PSTraceSource.NewArgumentNullException("commandName");
throw PSTraceSource.NewArgumentNullException(nameof(commandName));
}
string errorId = "ErrorMalformedDataFromRemoteCommand";
@ -585,7 +585,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(commandNames))
{
throw PSTraceSource.NewArgumentNullException("commandNames");
throw PSTraceSource.NewArgumentNullException(nameof(commandNames));
}
string errorId = "ErrorCommandSkippedBecauseOfShadowing";
@ -606,7 +606,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(commandName))
{
throw PSTraceSource.NewArgumentNullException("commandName");
throw PSTraceSource.NewArgumentNullException(nameof(commandName));
}
string errorId = "ErrorSkippedNonRequestedCommand";
@ -627,7 +627,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(typeName))
{
throw PSTraceSource.NewArgumentNullException("typeName");
throw PSTraceSource.NewArgumentNullException(nameof(typeName));
}
string errorId = "ErrorSkippedNonRequestedTypeDefinition";
@ -648,7 +648,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(commandName))
{
throw PSTraceSource.NewArgumentNullException("commandName");
throw PSTraceSource.NewArgumentNullException(nameof(commandName));
}
string errorId = "ErrorSkippedUnsafeCommandName";
@ -669,18 +669,18 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(aliasName))
{
throw PSTraceSource.NewArgumentNullException("aliasName");
throw PSTraceSource.NewArgumentNullException(nameof(aliasName));
}
string errorId = "ErrorCouldntResolveAlias";
@ -776,7 +776,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(commandName))
{
throw PSTraceSource.NewArgumentNullException("commandName");
throw PSTraceSource.NewArgumentNullException(nameof(commandName));
}
string errorId = "ErrorNoResultsFromRemoteEnd";
@ -872,7 +872,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(commandName))
{
throw PSTraceSource.NewArgumentNullException("commandName");
throw PSTraceSource.NewArgumentNullException(nameof(commandName));
}
if (this.AllowClobber.IsPresent)
@ -1270,7 +1270,7 @@ namespace Microsoft.PowerShell.Commands
{
if (deserializedParameterMetadata == null)
{
throw PSTraceSource.NewArgumentNullException("deserializedParameterMetadata");
throw PSTraceSource.NewArgumentNullException(nameof(deserializedParameterMetadata));
}
string name = GetPropertyValue<string>("Get-Command", deserializedParameterMetadata, "Name");
@ -1311,7 +1311,7 @@ namespace Microsoft.PowerShell.Commands
{
if (deserializedCommandInfo == null)
{
throw PSTraceSource.NewArgumentNullException("deserializedCommandInfo");
throw PSTraceSource.NewArgumentNullException(nameof(deserializedCommandInfo));
}
string name = GetPropertyValue<string>("Get-Command", deserializedCommandInfo, "Name");
@ -1964,7 +1964,7 @@ namespace Microsoft.PowerShell.Commands
{
if (name == null)
{
throw PSTraceSource.NewArgumentNullException("name");
throw PSTraceSource.NewArgumentNullException(nameof(name));
}
StringBuilder result = new StringBuilder(name.Length);
@ -2014,7 +2014,7 @@ namespace Microsoft.PowerShell.Commands
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
GenerateTopComment(writer);
@ -2087,7 +2087,7 @@ $script:MyModule = $MyInvocation.MyCommand.ScriptBlock.Module
{
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 @@ function Write-PSImplicitRemotingMessage
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
writer.Write(HelperFunctionsWriteMessage);
@ -2177,7 +2177,7 @@ if ($PSSessionOverride) {{ Set-PSImplicitRemotingSession $PSSessionOverride }}
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
string runspaceNameTemplate = StringUtil.Format(ImplicitRemotingStrings.ProxyRunspaceNameTemplate);
@ -2208,7 +2208,7 @@ function Get-PSImplicitRemotingSessionOption
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
writer.Write(
@ -2403,7 +2403,7 @@ function Get-PSImplicitRemotingSession
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
string hashString;
@ -2752,7 +2752,7 @@ function Get-PSImplicitRemotingClientSideParameters
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
writer.Write(HelperFunctionsModifyParameters);
@ -2831,7 +2831,7 @@ function Get-PSImplicitRemotingClientSideParameters
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
string functionNameForString = CodeGeneration.EscapeSingleQuotedStringContent(commandMetadata.Name);
@ -2853,12 +2853,12 @@ function Get-PSImplicitRemotingClientSideParameters
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
if (listOfCommandMetadata == null)
{
throw PSTraceSource.NewArgumentNullException("listOfCommandMetadata");
throw PSTraceSource.NewArgumentNullException(nameof(listOfCommandMetadata));
}
this.GenerateSectionSeparator(writer);
@ -2880,12 +2880,12 @@ function Get-PSImplicitRemotingClientSideParameters
{
if (writer == null)
{
throw PSTraceSource.NewArgumentNullException("writer");
throw PSTraceSource.NewArgumentNullException(nameof(writer));
}
if (listOfCommandMetadata == null)
{
throw PSTraceSource.NewArgumentNullException("listOfCommandMetadata");
throw PSTraceSource.NewArgumentNullException(nameof(listOfCommandMetadata));
}
this.GenerateSectionSeparator(writer);
@ -2899,7 +2899,7 @@ function Get-PSImplicitRemotingClientSideParameters
{
if (listOfCommandMetadata == null)
{
throw PSTraceSource.NewArgumentNullException("listOfCommandMetadata");
throw PSTraceSource.NewArgumentNullException(nameof(listOfCommandMetadata));
}
List<string> listOfCommandNames = new List<string>();
@ -2915,7 +2915,7 @@ function Get-PSImplicitRemotingClientSideParameters
{
if (listOfStrings == null)
{
throw PSTraceSource.NewArgumentNullException("listOfStrings");
throw PSTraceSource.NewArgumentNullException(nameof(listOfStrings));
}
StringBuilder arrayString = new StringBuilder();
@ -2976,12 +2976,12 @@ function Get-PSImplicitRemotingClientSideParameters
{
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();

View file

@ -25,7 +25,7 @@ namespace Microsoft.PowerShell.Commands
{
if (wildcardPatternsStrings == null)
{
throw new ArgumentNullException("wildcardPatternsStrings");
throw new ArgumentNullException(nameof(wildcardPatternsStrings));
}
_wildcardPatterns = new WildcardPattern[wildcardPatternsStrings.Length];

View file

@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Name;
@ -71,7 +71,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Members["Name"].Value as string;

View file

@ -21,7 +21,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Name;
@ -37,7 +37,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Members["Name"].Value as string;

View file

@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Name;
@ -50,7 +50,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Members["Name"].Value as string;

View file

@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Name;
@ -41,7 +41,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.Name = other.Members["Name"].Value as string;

View file

@ -22,7 +22,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.FullName = other.FullName;
@ -51,7 +51,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandExtension
{
if (other == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException(nameof(other));
}
this.IsEnum = (bool)(other.Members["IsEnum"].Value);

View file

@ -121,7 +121,7 @@ namespace Microsoft.PowerShell.Commands
{
if (value == null)
{
throw PSTraceSource.NewArgumentNullException("value");
throw PSTraceSource.NewArgumentNullException(nameof(value));
}
Offset64 = offset;
@ -150,7 +150,7 @@ namespace Microsoft.PowerShell.Commands
{
if (value == null)
{
throw PSTraceSource.NewArgumentNullException("value");
throw PSTraceSource.NewArgumentNullException(nameof(value));
}
Offset64 = offset;
@ -179,7 +179,7 @@ namespace Microsoft.PowerShell.Commands
{
if (value == null)
{
throw PSTraceSource.NewArgumentNullException("value");
throw PSTraceSource.NewArgumentNullException(nameof(value));
}
Bytes = value;

View file

@ -380,7 +380,7 @@ namespace Microsoft.PowerShell.Commands
/// <param name="response"></param>
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 @@ namespace Microsoft.PowerShell.Commands
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);

View file

@ -751,7 +751,7 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
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));

View file

@ -182,7 +182,7 @@ namespace Microsoft.PowerShell.Commands
private void SetResponse(HttpResponseMessage response, Stream contentStream)
{
if (response == null) { throw new ArgumentNullException("response"); }
if (response == null) { throw new ArgumentNullException(nameof(response)); }
BaseResponse = response;

View file

@ -31,7 +31,7 @@ namespace Microsoft.PowerShell.Commands
/// <param name="response"></param>
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)

View file

@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.Commands
{
if (address == null)
{
throw new ArgumentNullException("address");
throw new ArgumentNullException(nameof(address));
}
_proxyAddress = address;
@ -50,7 +50,7 @@ namespace Microsoft.PowerShell.Commands
{
if (destination == null)
{
throw new ArgumentNullException("destination");
throw new ArgumentNullException(nameof(destination));
}
if (destination.IsLoopback)

View file

@ -31,7 +31,7 @@ namespace Microsoft.PowerShell.Commands
{
if (cmdlet == null)
{
throw new PSArgumentNullException("cmdlet");
throw new PSArgumentNullException(nameof(cmdlet));
}
Diagnostics.Assert(

View file

@ -334,12 +334,12 @@ namespace Microsoft.PowerShell.Commands
{
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;

View file

@ -31,7 +31,7 @@ namespace Microsoft.PowerShell
{
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

View file

@ -1084,7 +1084,7 @@ namespace Microsoft.PowerShell
Dbg.Assert(!consoleHandle.IsClosed, "ConsoleHandle is closed");
if (contents == null)
{
throw PSTraceSource.NewArgumentNullException("contents");
throw PSTraceSource.NewArgumentNullException(nameof(contents));
}
uint codePage;

View file

@ -735,7 +735,7 @@ namespace Microsoft.PowerShell
public ConsoleColorProxy(ConsoleHostUserInterface ui)
{
if (ui == null) throw new ArgumentNullException("ui");
if (ui == null) throw new ArgumentNullException(nameof(ui));
_ui = ui;
}

View file

@ -609,7 +609,7 @@ namespace Microsoft.PowerShell
{
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 @@ namespace Microsoft.PowerShell
{
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 @@ namespace Microsoft.PowerShell
// 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 @@ namespace Microsoft.PowerShell
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 @@ namespace Microsoft.PowerShell
{
if (leftExisting[r, 0].BufferCellType == BufferCellType.Leading)
{
throw PSTraceSource.NewArgumentException("fill");
throw PSTraceSource.NewArgumentException(nameof(fill));
}
}
}
@ -1014,7 +1014,7 @@ namespace Microsoft.PowerShell
{
if (charLength == 2)
{
throw PSTraceSource.NewArgumentException("fill");
throw PSTraceSource.NewArgumentException(nameof(fill));
}
}
else
@ -1030,7 +1030,7 @@ namespace Microsoft.PowerShell
{
if (rightExisting[r, 0].BufferCellType == BufferCellType.Leading)
{
throw PSTraceSource.NewArgumentException("fill");
throw PSTraceSource.NewArgumentException(nameof(fill));
}
}
}
@ -1040,7 +1040,7 @@ namespace Microsoft.PowerShell
{
if (rightExisting[r, 0].BufferCellType == BufferCellType.Leading ^ charLength == 2)
{
throw PSTraceSource.NewArgumentException("fill");
throw PSTraceSource.NewArgumentException(nameof(fill));
}
}
}
@ -1091,14 +1091,14 @@ namespace Microsoft.PowerShell
// 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");
}

View file

@ -97,12 +97,12 @@ namespace Microsoft.PowerShell
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 @@ namespace Microsoft.PowerShell
descIndex++;
if (desc == null)
{
throw PSTraceSource.NewArgumentException("descriptions",
throw PSTraceSource.NewArgumentException(nameof(descriptions),
ConsoleHostUserInterfaceStrings.NullErrorTemplate,
string.Format(CultureInfo.InvariantCulture, "descriptions[{0}]", descIndex));
}

View file

@ -46,18 +46,18 @@ namespace Microsoft.PowerShell
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");
}
if ((defaultChoice < -1) || (defaultChoice >= choices.Count))
{
throw PSTraceSource.NewArgumentOutOfRangeException("defaultChoice", defaultChoice,
throw PSTraceSource.NewArgumentOutOfRangeException(nameof(defaultChoice), defaultChoice,
ConsoleHostUserInterfaceStrings.InvalidDefaultChoiceErrorTemplate, "defaultChoice", "choice");
}
@ -175,12 +175,12 @@ namespace Microsoft.PowerShell
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");
}

View file

@ -27,7 +27,7 @@ namespace Microsoft.PowerShell
internal
ProgressPane(ConsoleHostUserInterface ui)
{
if (ui == null) throw new ArgumentNullException("ui");
if (ui == null) throw new ArgumentNullException(nameof(ui));
_ui = ui;
_rawui = ui.RawUI;
}

View file

@ -38,12 +38,12 @@ namespace System.Diagnostics.Eventing
{
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 @@ namespace System.Diagnostics.Eventing
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;

View file

@ -435,7 +435,7 @@ namespace System.Diagnostics.Eventing
if (eventMessage == null)
{
throw new ArgumentNullException("eventMessage");
throw new ArgumentNullException(nameof(eventMessage));
}
if (IsEnabled(eventLevel, eventKeywords))
@ -619,7 +619,7 @@ namespace System.Diagnostics.Eventing
//
// 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 @@ namespace System.Diagnostics.Eventing
}
else
{
throw new ArgumentOutOfRangeException("eventPayload",
throw new ArgumentOutOfRangeException(nameof(eventPayload),
string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_MaxStringsExceeded, s_etwAPIMaxStringCount));
}
}

View file

@ -70,7 +70,7 @@ namespace System.Diagnostics.Eventing
: base(name)
{
if (delimiter == null)
throw new ArgumentNullException("delimiter");
throw new ArgumentNullException(nameof(delimiter));
if (delimiter.Length == 0)
throw new ArgumentException(DotNetEventingStrings.Argument_NeedNonemptyDelimiter);

View file

@ -287,7 +287,7 @@ namespace Microsoft.PowerShell.MarkdownRender
{
if (optionInfo == null)
{
throw new ArgumentNullException("optionInfo");
throw new ArgumentNullException(nameof(optionInfo));
}
options = optionInfo;

View file

@ -178,7 +178,7 @@ namespace Microsoft.PowerShell.Commands
{
if (instance == null)
{
throw PSTraceSource.NewArgumentNullException("instance");
throw PSTraceSource.NewArgumentNullException(nameof(instance));
}
else
{
@ -205,13 +205,13 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
{
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);

View file

@ -605,7 +605,7 @@ namespace Microsoft.PowerShell.Commands
X509StoreLocation user =
new X509StoreLocation(StoreLocation.CurrentUser);
s_storeLocations.Add(user);
AddItemToCache(StoreLocation.CurrentUser.ToString(),
AddItemToCache(nameof(StoreLocation.CurrentUser),
user);
//
@ -614,7 +614,7 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
if (string.IsNullOrEmpty(path))
{
throw PSTraceSource.NewArgumentException("path");
throw PSTraceSource.NewArgumentException(nameof(path));
}
// Normalize the path

View file

@ -555,7 +555,7 @@ namespace Microsoft.PowerShell.Commands
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"

View file

@ -63,7 +63,7 @@ namespace Microsoft.WSMan.Management
{
if (serverSession == null)
{
throw new ArgumentNullException("serverSession");
throw new ArgumentNullException(nameof(serverSession));
}
this.rootDocument = new XmlDocument();
@ -81,7 +81,7 @@ namespace Microsoft.WSMan.Management
{
if (string.IsNullOrEmpty(responseOfGet))
{
throw new ArgumentNullException("responseOfGet");
throw new ArgumentNullException(nameof(responseOfGet));
}
this.rootDocument.LoadXml(responseOfGet);
@ -103,7 +103,7 @@ namespace Microsoft.WSMan.Management
{
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 @@ namespace Microsoft.WSMan.Management
{
if (pathToNodeFromRoot == null)
{
throw new ArgumentNullException("pathToNodeFromRoot");
throw new ArgumentNullException(nameof(pathToNodeFromRoot));
}
XmlNode nodeToRemove =
@ -136,7 +136,7 @@ namespace Microsoft.WSMan.Management
}
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 @@ namespace Microsoft.WSMan.Management
{
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 @@ namespace Microsoft.WSMan.Management
{
if (pathFromRoot == null)
{
throw new ArgumentNullException("pathFromRoot");
throw new ArgumentNullException(nameof(pathFromRoot));
}
XmlNode requiredNode =

View file

@ -180,12 +180,12 @@ namespace Microsoft.WSMan.Management
{
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 @@ namespace Microsoft.WSMan.Management
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 );

View file

@ -78,7 +78,7 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
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);
}

View file

@ -298,7 +298,7 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration
if (engineIntrinsics == null)
{
throw PSTraceSource.NewArgumentNullException("engineIntrinsics");
throw PSTraceSource.NewArgumentNullException(nameof(engineIntrinsics));
}
return PsUtils.EvaluatePowerShellDataFileAsModuleManifest(
@ -372,7 +372,7 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration
{
if (string.IsNullOrEmpty(fullFilePath))
{
throw PSTraceSource.NewArgumentNullException("fullFilePath");
throw PSTraceSource.NewArgumentNullException(nameof(fullFilePath));
}
if (!File.Exists(fullFilePath))
@ -951,7 +951,7 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal
{
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 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal
{
if (string.IsNullOrWhiteSpace(fileName))
{
throw PSTraceSource.NewArgumentNullException("fileName");
throw PSTraceSource.NewArgumentNullException(nameof(fileName));
}
List<CimClass> listCimClass;
@ -1197,7 +1197,7 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal
{
if (string.IsNullOrWhiteSpace(moduleName))
{
throw PSTraceSource.NewArgumentNullException("moduleName");
throw PSTraceSource.NewArgumentNullException(nameof(moduleName));
}
var moduleFileName = moduleName + ".schema.mof";
@ -1214,7 +1214,7 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal
{
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 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal
{
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 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal
{
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 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal
{
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");

View file

@ -18,7 +18,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
internal TerminatingErrorContext(PSCmdlet command)
{
if (command == null)
throw PSTraceSource.NewArgumentNullException("command");
throw PSTraceSource.NewArgumentNullException(nameof(command));
_command = command;
}

View file

@ -171,7 +171,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
if (val == null)
{
throw PSTraceSource.NewArgumentNullException("val");
throw PSTraceSource.NewArgumentNullException(nameof(val));
}
// need to check the type:
@ -201,7 +201,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
return ex;
}
PSTraceSource.NewArgumentException("val");
PSTraceSource.NewArgumentException(nameof(val));
return null;
}

View file

@ -510,7 +510,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
// we assume FormatEntryData as a standard wrapper
if (fed == null)
{
PSTraceSource.NewArgumentNullException("fed");
PSTraceSource.NewArgumentNullException(nameof(fed));
}
if (fed.formatEntryInfo == null)

View file

@ -87,7 +87,7 @@ namespace System.Management.Automation.Runspaces
{
if (info == null)
{
throw new PSArgumentNullException("info");
throw new PSArgumentNullException(nameof(info));
}
int errorCount = info.GetInt32("ErrorCount");
@ -114,7 +114,7 @@ namespace System.Management.Automation.Runspaces
{
if (info == null)
{
throw new PSArgumentNullException("info");
throw new PSArgumentNullException(nameof(info));
}
base.GetObjectData(info, context);
@ -207,7 +207,7 @@ namespace System.Management.Automation.Runspaces
public void AppendFormatData(IEnumerable<ExtendedTypeDefinition> formatData)
{
if (formatData == null)
throw PSTraceSource.NewArgumentNullException("formatData");
throw PSTraceSource.NewArgumentNullException(nameof(formatData));
_formatDBMgr.AddFormatData(formatData, false);
}
@ -226,7 +226,7 @@ namespace System.Management.Automation.Runspaces
public void PrependFormatData(IEnumerable<ExtendedTypeDefinition> formatData)
{
if (formatData == null)
throw PSTraceSource.NewArgumentNullException("formatData");
throw PSTraceSource.NewArgumentNullException(nameof(formatData));
_formatDBMgr.AddFormatData(formatData, true);
}
@ -253,7 +253,7 @@ namespace System.Management.Automation.Runspaces
{
if (formatFiles == null)
{
throw PSTraceSource.NewArgumentNullException("formatFiles");
throw PSTraceSource.NewArgumentNullException(nameof(formatFiles));
}
_formatDBMgr = new TypeInfoDataBaseManager(formatFiles, true, authorizationManager, host);

View file

@ -376,22 +376,22 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
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 @@ namespace System.Management.Automation
public ExtendedTypeDefinition(string typeName, IEnumerable<FormatViewDefinition> 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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
{
if (string.IsNullOrEmpty(value))
if (value == null || type == DisplayEntryValueType.Property)
throw PSTraceSource.NewArgumentNullException("value");
throw PSTraceSource.NewArgumentNullException(nameof(value));
Value = value;
ValueType = type;

View file

@ -420,13 +420,13 @@ namespace System.Management.Automation
// 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

View file

@ -173,7 +173,7 @@ namespace System.Management.Automation
: 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 @@ namespace System.Management.Automation
: 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 @@ namespace System.Management.Automation
public ListControlEntry(IEnumerable<ListControlEntryItem> listItems, IEnumerable<string> 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<string>(selectedBy) };
foreach (ListControlEntryItem item in listItems)

View file

@ -306,7 +306,7 @@ namespace System.Management.Automation
if (tableControlRow == null)
throw PSTraceSource.NewArgumentNullException("tableControlRows");
if (tableControlColumnHeaders == null)
throw PSTraceSource.NewArgumentNullException("tableControlColumnHeaders");
throw PSTraceSource.NewArgumentNullException(nameof(tableControlColumnHeaders));
this.Rows.Add(tableControlRow);
foreach (TableControlColumnHeader header in tableControlColumnHeaders)
@ -355,7 +355,7 @@ namespace System.Management.Automation
public TableControlColumnHeader(string label, int width, Alignment alignment)
{
if (width < 0)
throw PSTraceSource.NewArgumentOutOfRangeException("width", width);
throw PSTraceSource.NewArgumentOutOfRangeException(nameof(width), width);
this.Label = label;
this.Width = width;
@ -467,7 +467,7 @@ namespace System.Management.Automation
public TableControlRow(IEnumerable<TableControlColumn> 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 @@ namespace System.Management.Automation
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))
{

View file

@ -145,7 +145,7 @@ namespace System.Management.Automation
public WideControl(IEnumerable<WideControlEntryItem> wideEntries) : this()
{
if (wideEntries == null)
throw PSTraceSource.NewArgumentNullException("wideEntries");
throw PSTraceSource.NewArgumentNullException(nameof(wideEntries));
foreach (WideControlEntryItem entryItem in wideEntries)
{
@ -157,7 +157,7 @@ namespace System.Management.Automation
public WideControl(IEnumerable<WideControlEntryItem> 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 @@ namespace System.Management.Automation
public WideControlEntryItem(DisplayEntry entry) : this()
{
if (entry == null)
throw PSTraceSource.NewArgumentNullException("entry");
throw PSTraceSource.NewArgumentNullException(nameof(entry));
this.DisplayEntry = entry;
}
@ -234,9 +234,9 @@ namespace System.Management.Automation
public WideControlEntryItem(DisplayEntry entry, IEnumerable<string> 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);

View file

@ -79,7 +79,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
if (string.IsNullOrEmpty(formatFile) || (!Path.IsPathRooted(formatFile)))
{
throw PSTraceSource.NewArgumentException("formatFile", FormatAndOutXmlLoadingStrings.FormatFileNotRooted, formatFile);
throw PSTraceSource.NewArgumentException(nameof(formatFile), FormatAndOutXmlLoadingStrings.FormatFileNotRooted, formatFile);
}
lock (_formatFileList)

View file

@ -193,16 +193,16 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
internal bool ProcessExpressionDirectives(XmlNode containerNode, List<XmlNode> unprocessedNodes)
{
if (containerNode == null)
throw PSTraceSource.NewArgumentNullException("containerNode");
throw PSTraceSource.NewArgumentNullException(nameof(containerNode));
string formatString = null;
TextToken textToken = null;

View file

@ -201,10 +201,10 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
private bool LoadCommonViewData(XmlNode viewNode, ViewDefinition view, List<XmlNode> 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;

View file

@ -93,7 +93,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
if (control == null)
{
throw PSTraceSource.NewArgumentNullException("control");
throw PSTraceSource.NewArgumentNullException(nameof(control));
}
ExecuteFormatControl(new TraversalInfo(0, maxTreeDepth), control,
@ -190,7 +190,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
if (so == null)
{
throw PSTraceSource.NewArgumentNullException("so");
throw PSTraceSource.NewArgumentNullException(nameof(so));
}
// guard against infinite loop

View file

@ -142,7 +142,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
Func<FormatInfoData> 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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
if (lst == null)
{
throw PSTraceSource.NewArgumentNullException("lst");
throw PSTraceSource.NewArgumentNullException(nameof(lst));
}
object memberRaw = FormatObjectDeserializer.GetProperty(so, property);

View file

@ -282,9 +282,9 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
: base(culture)
{
if (writeCall == null)
throw PSTraceSource.NewArgumentNullException("writeCall");
throw PSTraceSource.NewArgumentNullException(nameof(writeCall));
_writeCall = writeCall;
}

View file

@ -140,7 +140,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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++)

View file

@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
internal MshResolvedExpressionParameterAssociation(MshParameter parameter, PSPropertyExpression expression)
{
if (expression == null)
throw PSTraceSource.NewArgumentNullException("expression");
throw PSTraceSource.NewArgumentNullException(nameof(expression));
OriginatingParameter = parameter;
ResolvedExpression = expression;

View file

@ -71,7 +71,7 @@ namespace Microsoft.PowerShell.Commands
{
if (string.IsNullOrEmpty(s))
{
throw PSTraceSource.NewArgumentNullException("s");
throw PSTraceSource.NewArgumentNullException(nameof(s));
}
_stringValue = s;
@ -87,7 +87,7 @@ namespace Microsoft.PowerShell.Commands
{
if (scriptBlock == null)
{
throw PSTraceSource.NewArgumentNullException("scriptBlock");
throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock));
}
Script = scriptBlock;

View file

@ -252,9 +252,9 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
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 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
internal PromptHandler(string s, ConsoleLineOutput cmdlet)
{
if (string.IsNullOrEmpty(s))
throw PSTraceSource.NewArgumentNullException("s");
throw PSTraceSource.NewArgumentNullException(nameof(s));
_promptString = s;
_callingCmdlet = cmdlet;

View file

@ -21,8 +21,8 @@ namespace Microsoft.PowerShell.Cmdletization
/// <param name="returnValue">Return value of the method (ok to pass <c>null</c> if the method doesn't return anything).</param>
public MethodInvocationInfo(string name, IEnumerable<MethodParameter> 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;

View file

@ -19,22 +19,22 @@ namespace Microsoft.PowerShell.Cmdletization
{
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;

View file

@ -105,7 +105,7 @@ namespace Microsoft.PowerShell.Cim
{
if (propertyName == null)
{
throw new PSArgumentNullException("propertyName");
throw new PSArgumentNullException(nameof(propertyName));
}
// baseObject should never be null
@ -199,7 +199,7 @@ namespace Microsoft.PowerShell.Cim
{
if (adaptedProperty == null)
{
throw new ArgumentNullException("adaptedProperty");
throw new ArgumentNullException(nameof(adaptedProperty));
}
CimProperty cimProperty = adaptedProperty.Tag as CimProperty;
@ -213,7 +213,7 @@ namespace Microsoft.PowerShell.Cim
return ToStringCodeMethods.Type(typeof(string));
}
throw new ArgumentNullException("adaptedProperty");
throw new ArgumentNullException(nameof(adaptedProperty));
}
/// <summary>
@ -224,7 +224,7 @@ namespace Microsoft.PowerShell.Cim
{
if (adaptedProperty == null)
{
throw new ArgumentNullException("adaptedProperty");
throw new ArgumentNullException(nameof(adaptedProperty));
}
CimProperty cimProperty = adaptedProperty.Tag as CimProperty;
@ -239,7 +239,7 @@ namespace Microsoft.PowerShell.Cim
return cimInstance.GetCimSessionComputerName();
}
throw new ArgumentNullException("adaptedProperty");
throw new ArgumentNullException(nameof(adaptedProperty));
}
private void AddTypeNameHierarchy(IList<string> typeNamesWithNamespace, IList<string> typeNamesWithoutNamespace, string namespaceName, string className)
@ -288,7 +288,7 @@ namespace Microsoft.PowerShell.Cim
var cimInstance = baseObject as CimInstance;
if (cimInstance == null)
{
throw new ArgumentNullException("baseObject");
throw new ArgumentNullException(nameof(baseObject));
}
var typeNamesWithNamespace = new List<string>();
@ -381,7 +381,7 @@ namespace Microsoft.PowerShell.Cim
{
if (adaptedProperty == null)
{
throw new ArgumentNullException("adaptedProperty");
throw new ArgumentNullException(nameof(adaptedProperty));
}
if (!IsSettable(adaptedProperty))

View file

@ -39,12 +39,12 @@ namespace System.Management.Automation
{
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;

View file

@ -35,7 +35,7 @@ namespace System.Management.Automation
{
if (cmdlet == null)
{
throw PSTraceSource.NewArgumentNullException("cmdlet");
throw PSTraceSource.NewArgumentNullException(nameof(cmdlet));
}
_cmdlet = cmdlet;
@ -55,7 +55,7 @@ namespace System.Management.Automation
{
if (sessionState == null)
{
throw PSTraceSource.NewArgumentNullException("sessionState");
throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
}
_sessionState = sessionState;

View file

@ -38,7 +38,7 @@ namespace System.Management.Automation
{
if (cmdlet == null)
{
throw PSTraceSource.NewArgumentNullException("cmdlet");
throw PSTraceSource.NewArgumentNullException(nameof(cmdlet));
}
_cmdlet = cmdlet;
@ -59,7 +59,7 @@ namespace System.Management.Automation
{
if (sessionState == null)
{
throw PSTraceSource.NewArgumentNullException("sessionState");
throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
}
Item = new ItemCmdletProviderIntrinsics(sessionState);

View file

@ -44,7 +44,7 @@ namespace System.Management.Automation
{
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 @@ namespace System.Management.Automation
{
throw
PSTraceSource.NewArgumentException(
"name",
nameof(name),
DiscoveryExceptions.InvalidCmdletNameFormat,
name);
}
@ -105,12 +105,12 @@ namespace System.Management.Automation
{
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 @@ namespace System.Management.Automation
{
throw
PSTraceSource.NewArgumentException(
"name",
nameof(name),
DiscoveryExceptions.InvalidCmdletNameFormat,
name);
}

View file

@ -54,12 +54,12 @@ namespace System.Management.Automation
{
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 @@ namespace System.Management.Automation
{
if (parameters == null)
{
throw PSTraceSource.NewArgumentNullException("parameters");
throw PSTraceSource.NewArgumentNullException(nameof(parameters));
}
// Get all the matching arguments from the defaultParameterValues collection
@ -4409,7 +4409,7 @@ namespace System.Management.Automation
{
if (dictionary == null)
{
throw PSTraceSource.NewArgumentNullException("dictionary");
throw PSTraceSource.NewArgumentNullException(nameof(dictionary));
}
// Contains keys that are in bad format. For every bad format key, we should write out a warning message
// the first time we encounter it, and remove it from the $PSDefaultParameterValues
@ -4481,7 +4481,7 @@ namespace System.Management.Automation
{
if (key == null)
{
throw PSTraceSource.NewArgumentNullException("key");
throw PSTraceSource.NewArgumentNullException(nameof(key));
}
var strKey = key as string;
@ -4508,13 +4508,13 @@ namespace System.Management.Automation
{
if (key == null)
{
throw PSTraceSource.NewArgumentNullException("key");
throw PSTraceSource.NewArgumentNullException(nameof(key));
}
var strKey = key as string;
if (strKey == null)
{
throw PSTraceSource.NewArgumentException("key", ParameterBinderStrings.StringValueKeyExpected, key, key.GetType().FullName);
throw PSTraceSource.NewArgumentException(nameof(key), ParameterBinderStrings.StringValueKeyExpected, key, key.GetType().FullName);
}
string keyAfterTrim = strKey.Trim();
@ -4530,7 +4530,7 @@ namespace System.Management.Automation
return;
}
throw PSTraceSource.NewArgumentException("key", ParameterBinderStrings.KeyAlreadyAdded, key);
throw PSTraceSource.NewArgumentException(nameof(key), ParameterBinderStrings.KeyAlreadyAdded, key);
}
if (!CheckKeyIsValid(keyAfterTrim, ref cmdletName, ref parameterName))
@ -4555,7 +4555,7 @@ namespace System.Management.Automation
{
get
{
if (key == null) { throw PSTraceSource.NewArgumentNullException("key"); }
if (key == null) { throw PSTraceSource.NewArgumentNullException(nameof(key)); }
var strKey = key as string;
if (strKey == null) { return null; }
@ -4578,7 +4578,7 @@ namespace System.Management.Automation
{
if (key == null)
{
throw PSTraceSource.NewArgumentNullException("key");
throw PSTraceSource.NewArgumentNullException(nameof(key));
}
var strKey = key as string;

View file

@ -67,7 +67,7 @@ namespace Microsoft.PowerShell
{
if (largeIntegerInstance == null)
{
throw PSTraceSource.NewArgumentException("largeIntegerInstance");
throw PSTraceSource.NewArgumentException(nameof(largeIntegerInstance));
}
object largeIntObject = (object)largeIntegerInstance.BaseObject;
@ -111,7 +111,7 @@ namespace Microsoft.PowerShell
{
if (dnWithBinaryInstance == null)
{
throw PSTraceSource.NewArgumentException("dnWithBinaryInstance");
throw PSTraceSource.NewArgumentException(nameof(dnWithBinaryInstance));
}
object dnWithBinaryObject = (object)dnWithBinaryInstance.BaseObject;

View file

@ -484,7 +484,7 @@ namespace System.Management.Automation
{
if (providerId == null)
{
throw PSTraceSource.NewArgumentNullException("providerId");
throw PSTraceSource.NewArgumentNullException(nameof(providerId));
}
PathInfo result = SessionState.Path.CurrentProviderLocation(providerId);

View file

@ -72,7 +72,7 @@ namespace System.Management.Automation
{
if (cursorIndex > input.Length)
{
throw PSTraceSource.NewArgumentException("cursorIndex");
throw PSTraceSource.NewArgumentException(nameof(cursorIndex));
}
Token[] tokens;
@ -112,17 +112,17 @@ namespace System.Management.Automation
{
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
{
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
{
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.

View file

@ -207,7 +207,7 @@ namespace System.Management.Automation
}
private static readonly HashSet<string> s_keywordsToExcludeFromAddingAmpersand
= new HashSet<string>(StringComparer.OrdinalIgnoreCase) { TokenKind.InlineScript.ToString(), TokenKind.Configuration.ToString() };
= new HashSet<string>(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;

View file

@ -170,22 +170,22 @@ namespace System.Management.Automation
{
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;

View file

@ -34,7 +34,7 @@ namespace System.Management.Automation
{
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 @@ namespace System.Management.Automation
{
if (scriptBlock == null)
{
throw PSTraceSource.NewArgumentNullException("scriptBlock");
throw PSTraceSource.NewArgumentNullException(nameof(scriptBlock));
}
ScriptBlock = scriptBlock;
@ -176,12 +176,12 @@ namespace System.Management.Automation
{
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;

View file

@ -75,7 +75,7 @@ namespace System.Management.Automation.Language
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 @@ namespace System.Management.Automation.Language
internal AstArrayPair(string parameterName, ICollection<ExpressionAst> 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 @@ namespace System.Management.Automation.Language
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 @@ namespace System.Management.Automation.Language
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 @@ namespace System.Management.Automation.Language
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 @@ namespace System.Management.Automation.Language
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 @@ namespace System.Management.Automation.Language
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 @@ namespace System.Management.Automation.Language
{
if (command == null)
{
throw PSTraceSource.NewArgumentNullException("command");
throw PSTraceSource.NewArgumentNullException(nameof(command));
}
// initialize/reset the private members

View file

@ -133,7 +133,7 @@ namespace System.Management.Automation
{
if (context == null)
{
throw PSTraceSource.NewArgumentNullException("context");
throw PSTraceSource.NewArgumentNullException(nameof(context));
}
Context = context;
@ -202,7 +202,7 @@ namespace System.Management.Automation
{
if (string.IsNullOrEmpty(name))
{
throw PSTraceSource.NewArgumentException("name");
throw PSTraceSource.NewArgumentException(nameof(name));
}
if (newCmdletInfo == null)
@ -1525,7 +1525,7 @@ namespace System.Management.Automation
if (context == null)
{
throw PSTraceSource.NewArgumentNullException("context");
throw PSTraceSource.NewArgumentNullException(nameof(context));
}
// check the PSVariable
@ -1687,7 +1687,7 @@ namespace System.Management.Automation
{
if (string.IsNullOrEmpty(item))
{
throw PSTraceSource.NewArgumentException("item");
throw PSTraceSource.NewArgumentException(nameof(item));
}
int result = -1;

View file

@ -112,7 +112,7 @@ namespace System.Management.Automation
if (name == null)
{
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));
}
Name = name;
@ -287,7 +287,7 @@ namespace System.Management.Automation
{
if (string.IsNullOrEmpty(newName))
{
throw new ArgumentNullException("newName");
throw new ArgumentNullException(nameof(newName));
}
Name = newName;
@ -800,7 +800,7 @@ namespace System.Management.Automation
{
if (typeDefinitionAst == null)
{
throw PSTraceSource.NewArgumentNullException("typeDefinitionAst");
throw PSTraceSource.NewArgumentNullException(nameof(typeDefinitionAst));
}
TypeDefinitionAst = typeDefinitionAst;
@ -814,7 +814,7 @@ namespace System.Management.Automation
{
if (typeName == null)
{
throw PSTraceSource.NewArgumentNullException("typeName");
throw PSTraceSource.NewArgumentNullException(nameof(typeName));
}
_type = typeName.GetReflectionType();

View file

@ -105,7 +105,7 @@ namespace System.Management.Automation
{
if (commandInfo == null)
{
throw PSTraceSource.NewArgumentNullException("commandInfo");
throw PSTraceSource.NewArgumentNullException(nameof(commandInfo));
}
while (commandInfo is AliasInfo)
{
@ -162,7 +162,7 @@ namespace System.Management.Automation
{
if (other == null)
{
throw PSTraceSource.NewArgumentNullException("other");
throw PSTraceSource.NewArgumentNullException(nameof(other));
}
Name = other.Name;
@ -315,7 +315,7 @@ namespace System.Management.Automation
{
if (string.IsNullOrEmpty(commandName))
{
throw PSTraceSource.NewArgumentException("commandName");
throw PSTraceSource.NewArgumentException(nameof(commandName));
}
CommandMetadata result = null;
@ -369,7 +369,7 @@ namespace System.Management.Automation
{
if (string.IsNullOrEmpty(commandName))
{
throw PSTraceSource.NewArgumentException("commandName");
throw PSTraceSource.NewArgumentException(nameof(commandName));
}
Name = commandName;
@ -412,7 +412,7 @@ namespace System.Management.Automation
{
if (scriptblock == null)
{
throw PSTraceSource.NewArgumentException("scriptblock");
throw PSTraceSource.NewArgumentException(nameof(scriptblock));
}
CmdletBindingAttribute cmdletBindingAttribute = scriptblock.CmdletBindingAttribute;
@ -725,7 +725,7 @@ namespace System.Management.Automation
{
if (attribute == null)
{
throw PSTraceSource.NewArgumentNullException("attribute");
throw PSTraceSource.NewArgumentNullException(nameof(attribute));
}
// Process the default parameter set name

View file

@ -104,7 +104,7 @@ namespace System.Management.Automation
Cmdlet cmdlet = command as Cmdlet;
if (cmdlet == null)
{
throw PSTraceSource.NewArgumentException("command");
throw PSTraceSource.NewArgumentException(nameof(command));
}
ParameterBinderBase parameterBinder;

View file

@ -35,7 +35,7 @@ namespace System.Management.Automation
{
if (commandInfo == null)
{
throw PSTraceSource.NewArgumentNullException("commandInfo");
throw PSTraceSource.NewArgumentNullException(nameof(commandInfo));
}
if (commandInfo is IScriptCommandInfo scriptCommand)
@ -278,12 +278,12 @@ namespace System.Management.Automation
{
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);

View file

@ -28,7 +28,7 @@ namespace System.Management.Automation.Internal
{
if (commandRuntime == null)
{
throw PSTraceSource.NewArgumentNullException("commandRuntime");
throw PSTraceSource.NewArgumentNullException(nameof(commandRuntime));
}
_commandRuntime = commandRuntime;

View file

@ -37,7 +37,7 @@ namespace System.Management.Automation
{
if (runtimeDefinedParameter == null)
{
throw PSTraceSource.NewArgumentNullException("runtimeDefinedParameter");
throw PSTraceSource.NewArgumentNullException(nameof(runtimeDefinedParameter));
}
this.Name = runtimeDefinedParameter.Name;
@ -123,7 +123,7 @@ namespace System.Management.Automation
{
if (member == null)
{
throw PSTraceSource.NewArgumentNullException("member");
throw PSTraceSource.NewArgumentNullException(nameof(member));
}
this.Name = member.Name;
@ -146,7 +146,7 @@ namespace System.Management.Automation
{
ArgumentException e =
PSTraceSource.NewArgumentException(
"member",
nameof(member),
DiscoveryExceptions.CompiledCommandParameterMemberMustBeFieldOrProperty);
throw e;

View file

@ -39,7 +39,7 @@ namespace System.Management.Automation
{
if (cmdlet == null)
{
throw PSTraceSource.NewArgumentNullException("cmdlet");
throw PSTraceSource.NewArgumentNullException(nameof(cmdlet));
}
_cmdlet = cmdlet;
@ -59,7 +59,7 @@ namespace System.Management.Automation
{
if (sessionState == null)
{
throw PSTraceSource.NewArgumentNullException("sessionState");
throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
}
_sessionState = sessionState;

View file

@ -1856,7 +1856,7 @@ namespace System.Management.Automation
{
if (resultType == null)
{
throw PSTraceSource.NewArgumentNullException("resultType");
throw PSTraceSource.NewArgumentNullException(nameof(resultType));
}
bool isArgumentByRef;
@ -1911,7 +1911,7 @@ namespace System.Management.Automation
{
if (resultType == null)
{
throw PSTraceSource.NewArgumentNullException("resultType");
throw PSTraceSource.NewArgumentNullException(nameof(resultType));
}
PSObject mshObj = valueToConvert as PSObject;

View file

@ -219,7 +219,7 @@ namespace System.Management.Automation
public PSCredential(PSObject pso)
{
if (pso == null)
throw PSTraceSource.NewArgumentNullException("pso");
throw PSTraceSource.NewArgumentNullException(nameof(pso));
if (pso.Properties["UserName"] != null)
{

View file

@ -127,7 +127,7 @@ namespace System.Management.Automation
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
throw PSTraceSource.NewArgumentNullException(nameof(path));
}
if (!DriveBeingCreated)
@ -271,7 +271,7 @@ namespace System.Management.Automation
{
if (driveInfo == null)
{
throw PSTraceSource.NewArgumentNullException("driveInfo");
throw PSTraceSource.NewArgumentNullException(nameof(driveInfo));
}
_name = driveInfo.Name;
@ -326,17 +326,17 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
{
if (string.IsNullOrEmpty(newName))
{
throw PSTraceSource.NewArgumentException("newName");
throw PSTraceSource.NewArgumentException(nameof(newName));
}
_name = newName;
@ -534,7 +534,7 @@ namespace System.Management.Automation
{
if (newProvider == null)
{
throw PSTraceSource.NewArgumentNullException("newProvider");
throw PSTraceSource.NewArgumentNullException(nameof(newProvider));
}
_provider = newProvider;
@ -602,7 +602,7 @@ namespace System.Management.Automation
if (drive == null)
{
throw PSTraceSource.NewArgumentNullException("drive");
throw PSTraceSource.NewArgumentNullException(nameof(drive));
}
return string.Compare(Name, drive.Name, StringComparison.OrdinalIgnoreCase);
@ -631,7 +631,7 @@ namespace System.Management.Automation
{
ArgumentException e =
PSTraceSource.NewArgumentException(
"obj",
nameof(obj),
SessionStateStrings.OnlyAbleToComparePSDriveInfo);
throw e;
}

View file

@ -297,7 +297,7 @@ namespace System.Management.Automation
{
if (providerInfo == null)
{
throw PSTraceSource.NewArgumentNullException("providerInfo");
throw PSTraceSource.NewArgumentNullException(nameof(providerInfo));
}
Name = providerInfo.Name;
@ -394,17 +394,17 @@ namespace System.Management.Automation
// 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;

View file

@ -21,7 +21,7 @@ namespace System.Management.Automation
public DefaultCommandRuntime(List<object> outputList)
{
if (outputList == null)
throw new System.ArgumentNullException("outputList");
throw new System.ArgumentNullException(nameof(outputList));
_output = outputList;
}

View file

@ -38,7 +38,7 @@ namespace System.Management.Automation
{
if (sessionState == null)
{
throw PSTraceSource.NewArgumentNullException("sessionState");
throw PSTraceSource.NewArgumentNullException(nameof(sessionState));
}
_sessionState = sessionState;

View file

@ -37,7 +37,7 @@ namespace System.Management.Automation
{
if (context == null)
{
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));
}
_context = context;

View file

@ -420,7 +420,7 @@ namespace System.Management.Automation
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);

View file

@ -666,7 +666,7 @@ namespace System.Management.Automation
{
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
{
if (subscriber == null)
{
throw new ArgumentNullException("subscriber");
throw new ArgumentNullException(nameof(subscriber));
}
Delegate existingSubscriber = null;
@ -2362,7 +2362,7 @@ namespace System.Management.Automation
{
if (eventToAdd == null)
{
throw new ArgumentNullException("eventToAdd");
throw new ArgumentNullException(nameof(eventToAdd));
}
_eventCollection.Add(eventToAdd);
@ -2479,9 +2479,9 @@ namespace System.Management.Automation
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;

Some files were not shown because too many files have changed in this diff Show more