Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ dotnet_diagnostic.CA1505.severity = none
dotnet_diagnostic.CA1506.severity = none

# CA1507: Use nameof to express symbol names
dotnet_diagnostic.CA1507.severity = suggestion
dotnet_diagnostic.CA1507.severity = warning

# CA1508: Avoid dead conditional code
dotnet_diagnostic.CA1508.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected TSession[] Session
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

_session = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private bool FilterMatch(ManagementObject obj)
foreach (string desc in Description)
{
WildcardPattern wildcardpattern = WildcardPattern.Get(desc, WildcardOptions.IgnoreCase);
if (wildcardpattern.IsMatch((string)obj["Description"]))
if (wildcardpattern.IsMatch((string)obj[nameof(Description)]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here Description is a property name of ManagementObject.
Or can it be:

Suggested change
if (wildcardpattern.IsMatch((string)obj[nameof(Description)]))
if (wildcardpattern.IsMatch((string)obj[nameof(obj.Description)]))

Also what about "InstalledBy" in the file?

I suggest to revert such non-obvious changes here and below because we can break something tricky.

{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ private CommandMetadata RehydrateCommandMetadata(PSObject deserializedCommandInf

string name = GetPropertyValue<string>("Get-Command", deserializedCommandInfo, "Name");

CommandTypes commandType = GetPropertyValue<CommandTypes>("Get-Command", deserializedCommandInfo, "CommandType");
CommandTypes commandType = GetPropertyValue<CommandTypes>("Get-Command", deserializedCommandInfo, nameof(CommandType));
if (commandType == CommandTypes.Alias)
{
resolvedCommandName = GetPropertyValue<string>("Get-Command", deserializedCommandInfo, "ResolvedCommandName", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ public string[] Exclude
{
// null check is not needed (because of ValidateNotNullOrEmpty),
// but we have to include it to silence OACR
_excludeStrings = value ?? throw PSTraceSource.NewArgumentNullException("value");
_excludeStrings = value ?? throw PSTraceSource.NewArgumentNullException(nameof(value));

_exclude = new WildcardPattern[_excludeStrings.Length];
for (int i = 0; i < _excludeStrings.Length; i++)
Expand Down Expand Up @@ -1384,7 +1384,7 @@ public Encoding Encoding
{
// null check is not needed (because of ValidateNotNullOrEmpty),
// but we have to include it to silence OACR
_context = value ?? throw PSTraceSource.NewArgumentNullException("value");
_context = value ?? throw PSTraceSource.NewArgumentNullException(nameof(value));

if (_context.Length == 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override object Transform(EngineIntrinsics engineIntrinsics, object input
{
if (engineIntrinsics?.Host?.UI == null)
{
throw PSTraceSource.NewArgumentNullException("engineIntrinsics");
throw PSTraceSource.NewArgumentNullException(nameof(engineIntrinsics));
}

if (inputData == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,55 +89,55 @@ internal bool HasHostWindow
{
get
{
return (bool)_graphicalHostReflectionWrapper.GetPropertyValue("HasHostWindow");
return (bool)_graphicalHostReflectionWrapper.GetPropertyValue(nameof(HasHostWindow));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same. HasHostWindow is a property of GraphicalHostReflectionWrapper.

I see the same patterns below.

}
}

internal AutoResetEvent WindowClosed
{
get
{
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue("WindowClosed");
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue(nameof(WindowClosed));
}
}

internal AutoResetEvent HelpNeeded
{
get
{
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue("HelpNeeded");
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue(nameof(HelpNeeded));
}
}

internal AutoResetEvent ImportModuleNeeded
{
get
{
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue("ImportModuleNeeded");
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue(nameof(ImportModuleNeeded));
}
}

internal AutoResetEvent WindowLoaded
{
get
{
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue("WindowLoaded");
return (AutoResetEvent)_graphicalHostReflectionWrapper.GetPropertyValue(nameof(WindowLoaded));
}
}

internal string CommandNeedingHelp
{
get
{
return (string)_graphicalHostReflectionWrapper.GetPropertyValue("CommandNeedingHelp");
return (string)_graphicalHostReflectionWrapper.GetPropertyValue(nameof(CommandNeedingHelp));
}
}

internal string ParentModuleNeedingImportModule
{
get
{
return (string)_graphicalHostReflectionWrapper.GetPropertyValue("ParentModuleNeedingImportModule");
return (string)_graphicalHostReflectionWrapper.GetPropertyValue(nameof(ParentModuleNeedingImportModule));
}
}

Expand Down Expand Up @@ -175,15 +175,15 @@ internal double ScreenWidth
{
get
{
return (double)_graphicalHostReflectionWrapper.GetStaticPropertyValue("ScreenWidth");
return (double)_graphicalHostReflectionWrapper.GetStaticPropertyValue(nameof(ScreenWidth));
}
}

internal double ScreenHeight
{
get
{
return (double)_graphicalHostReflectionWrapper.GetStaticPropertyValue("ScreenHeight");
return (double)_graphicalHostReflectionWrapper.GetStaticPropertyValue(nameof(ScreenHeight));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override
}
else
{
throw PSTraceSource.NewArgumentException("value", ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
throw PSTraceSource.NewArgumentException(nameof(value), ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
}
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public override
}
else
{
throw PSTraceSource.NewArgumentException("value", ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
throw PSTraceSource.NewArgumentException(nameof(value), ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
}
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public override

ConsoleHandle handle = GetBufferInfo(out bufferInfo);

CheckCoordinateWithinBuffer(ref value, ref bufferInfo, "value");
CheckCoordinateWithinBuffer(ref value, ref bufferInfo, nameof(value));
ConsoleControl.SetConsoleCursorPosition(handle, value);
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ public override
}
else
{
throw PSTraceSource.NewArgumentOutOfRangeException("value", value,
throw PSTraceSource.NewArgumentOutOfRangeException(nameof(value), value,
ConsoleHostRawUserInterfaceStrings.InvalidCursorSizeError);
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ public override
if (win32exception != null &&
win32exception.NativeErrorCode == 0x57)
{
throw PSTraceSource.NewArgumentOutOfRangeException("value", value,
throw PSTraceSource.NewArgumentOutOfRangeException(nameof(value), value,
ConsoleHostRawUserInterfaceStrings.InvalidBufferSizeError);
}
else
Expand Down Expand Up @@ -490,13 +490,13 @@ public override

if (r.Right < r.Left)
{
throw PSTraceSource.NewArgumentOutOfRangeException("value", value,
throw PSTraceSource.NewArgumentOutOfRangeException(nameof(value), value,
ConsoleHostRawUserInterfaceStrings.WindowTooNarrowError);
}

if (r.Bottom < r.Top)
{
throw PSTraceSource.NewArgumentOutOfRangeException("value", value,
throw PSTraceSource.NewArgumentOutOfRangeException(nameof(value), value,
ConsoleHostRawUserInterfaceStrings.WindowTooShortError);
}

Expand Down Expand Up @@ -819,19 +819,19 @@ public override string WindowTitle
}
else if (value.Length < MinWindowTitleLength)
{
throw PSTraceSource.NewArgumentException("value", ConsoleHostRawUserInterfaceStrings.WindowTitleTooShortError);
throw PSTraceSource.NewArgumentException(nameof(value), ConsoleHostRawUserInterfaceStrings.WindowTitleTooShortError);
}
else
{
throw PSTraceSource.NewArgumentException("value",
throw PSTraceSource.NewArgumentException(nameof(value),
ConsoleHostRawUserInterfaceStrings
.WindowTitleTooLongErrorTemplate,
MaxWindowTitleLength);
}
}
else
{
throw PSTraceSource.NewArgumentNullException("value");
throw PSTraceSource.NewArgumentNullException(nameof(value));
}
}
}
Expand Down Expand Up @@ -1604,7 +1604,7 @@ public override void SetBufferContents(Coordinates origin,
// if there are no contents, there is nothing to set the buffer to
if (contents == null)
{
PSTraceSource.NewArgumentNullException("contents");
PSTraceSource.NewArgumentNullException(nameof(contents));
}
// if the cursor is on the last line, we need to make more space to print the specified buffer
if (origin.Y == BufferSize.Height - 1 && origin.X >= BufferSize.Width)
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/Credential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static explicit operator NetworkCredential(PSCredential credential)

if (credential == null)
{
throw PSTraceSource.NewArgumentNullException("credential");
throw PSTraceSource.NewArgumentNullException(nameof(credential));
}

return credential.GetNetworkCredential();
Expand Down
26 changes: 13 additions & 13 deletions src/System.Management.Automation/engine/ErrorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,10 +1204,10 @@ internal void ToPSObjectForRemoting(PSObject dest)

private void ToPSObjectForRemoting(PSObject dest, bool serializeExtInfo)
{
RemotingEncoder.AddNoteProperty<Exception>(dest, "Exception", delegate () { return Exception; });
RemotingEncoder.AddNoteProperty<object>(dest, "TargetObject", delegate () { return TargetObject; });
RemotingEncoder.AddNoteProperty<string>(dest, "FullyQualifiedErrorId", delegate () { return FullyQualifiedErrorId; });
RemotingEncoder.AddNoteProperty<InvocationInfo>(dest, "InvocationInfo", delegate () { return InvocationInfo; });
RemotingEncoder.AddNoteProperty<Exception>(dest, nameof(Exception), delegate () { return Exception; });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, is the reference to Exception right?
Below in the file too.

RemotingEncoder.AddNoteProperty<object>(dest, nameof(TargetObject), delegate () { return TargetObject; });
RemotingEncoder.AddNoteProperty<string>(dest, nameof(FullyQualifiedErrorId), delegate () { return FullyQualifiedErrorId; });
RemotingEncoder.AddNoteProperty<InvocationInfo>(dest, nameof(InvocationInfo), delegate () { return InvocationInfo; });
RemotingEncoder.AddNoteProperty<int>(dest, "ErrorCategory_Category", delegate () { return (int)CategoryInfo.Category; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Activity", delegate () { return CategoryInfo.Activity; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Reason", delegate () { return CategoryInfo.Reason; });
Expand All @@ -1223,13 +1223,13 @@ private void ToPSObjectForRemoting(PSObject dest, bool serializeExtInfo)

if (!serializeExtInfo || this.InvocationInfo == null)
{
RemotingEncoder.AddNoteProperty(dest, "SerializeExtendedInfo", () => false);
RemotingEncoder.AddNoteProperty(dest, nameof(SerializeExtendedInfo), () => false);
}
else
{
RemotingEncoder.AddNoteProperty(dest, "SerializeExtendedInfo", () => true);
RemotingEncoder.AddNoteProperty(dest, nameof(SerializeExtendedInfo), () => true);
this.InvocationInfo.ToPSObjectForRemoting(dest);
RemotingEncoder.AddNoteProperty<object>(dest, "PipelineIterationInfo", delegate () { return PipelineIterationInfo; });
RemotingEncoder.AddNoteProperty<object>(dest, nameof(PipelineIterationInfo), delegate () { return PipelineIterationInfo; });
}

if (!string.IsNullOrEmpty(this.ScriptStackTrace))
Expand Down Expand Up @@ -1291,10 +1291,10 @@ private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
}

// Get Exception
PSObject serializedException = RemotingDecoder.GetPropertyValue<PSObject>(serializedErrorRecord, "Exception");
PSObject serializedException = RemotingDecoder.GetPropertyValue<PSObject>(serializedErrorRecord, nameof(Exception));

// Get Target object
object targetObject = RemotingDecoder.GetPropertyValue<object>(serializedErrorRecord, "TargetObject");
object targetObject = RemotingDecoder.GetPropertyValue<object>(serializedErrorRecord, nameof(TargetObject));

string exceptionMessage = null;
if (serializedException != null)
Expand All @@ -1307,7 +1307,7 @@ private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
}

// Get FullyQualifiedErrorId
string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "FullyQualifiedErrorId") ??
string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, nameof(FullyQualifiedErrorId)) ??
"fullyQualifiedErrorId";

// Get ErrorCategory...
Expand All @@ -1323,7 +1323,7 @@ private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
// Get InvocationInfo (optional property)
PSObject invocationInfo = Microsoft.PowerShell.DeserializingTypeConverter.GetPropertyValue<PSObject>(
serializedErrorRecord,
"InvocationInfo",
nameof(InvocationInfo),
Microsoft.PowerShell.DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk);

// Get Error Detail (these note properties are optional, so can't right now use RemotingDecoder...)
Expand Down Expand Up @@ -1359,13 +1359,13 @@ private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
//
// Get the InvocationInfo
//
_serializeExtendedInfo = RemotingDecoder.GetPropertyValue<bool>(serializedErrorRecord, "SerializeExtendedInfo");
_serializeExtendedInfo = RemotingDecoder.GetPropertyValue<bool>(serializedErrorRecord, nameof(SerializeExtendedInfo));

if (_serializeExtendedInfo)
{
_invocationInfo = new InvocationInfo(serializedErrorRecord);

ArrayList iterationInfo = RemotingDecoder.GetPropertyValue<ArrayList>(serializedErrorRecord, "PipelineIterationInfo");
ArrayList iterationInfo = RemotingDecoder.GetPropertyValue<ArrayList>(serializedErrorRecord, nameof(PipelineIterationInfo));
if (iterationInfo != null)
{
_pipelineIterationInfo = new ReadOnlyCollection<int>((int[])iterationInfo.ToArray(typeof(Int32)));
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public string[] ParameterName
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

_parameterNames = value;
Expand Down Expand Up @@ -316,7 +316,7 @@ public PSTypeName[] ParameterType
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

// if '...CimInstance#Win32_Process' is specified, then exclude '...CimInstance'
Expand Down
18 changes: 9 additions & 9 deletions src/System.Management.Automation/engine/InformationRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,22 @@ internal static InformationRecord FromPSObjectForRemoting(PSObject inputObject)
{
InformationRecord informationRecord = new InformationRecord();

informationRecord.MessageData = RemotingDecoder.GetPropertyValue<object>(inputObject, "MessageData");
informationRecord.Source = RemotingDecoder.GetPropertyValue<string>(inputObject, "Source");
informationRecord.TimeGenerated = RemotingDecoder.GetPropertyValue<DateTime>(inputObject, "TimeGenerated");
informationRecord.MessageData = RemotingDecoder.GetPropertyValue<object>(inputObject, nameof(MessageData));
informationRecord.Source = RemotingDecoder.GetPropertyValue<string>(inputObject, nameof(Source));
informationRecord.TimeGenerated = RemotingDecoder.GetPropertyValue<DateTime>(inputObject, nameof(TimeGenerated));

informationRecord.Tags = new List<string>();
System.Collections.ArrayList tagsArrayList = RemotingDecoder.GetPropertyValue<System.Collections.ArrayList>(inputObject, "Tags");
System.Collections.ArrayList tagsArrayList = RemotingDecoder.GetPropertyValue<System.Collections.ArrayList>(inputObject, nameof(Tags));
foreach (string tag in tagsArrayList)
{
informationRecord.Tags.Add(tag);
}

informationRecord.User = RemotingDecoder.GetPropertyValue<string>(inputObject, "User");
informationRecord.Computer = RemotingDecoder.GetPropertyValue<string>(inputObject, "Computer");
informationRecord.ProcessId = RemotingDecoder.GetPropertyValue<uint>(inputObject, "ProcessId");
informationRecord.NativeThreadId = RemotingDecoder.GetPropertyValue<uint>(inputObject, "NativeThreadId");
informationRecord.ManagedThreadId = RemotingDecoder.GetPropertyValue<uint>(inputObject, "ManagedThreadId");
informationRecord.User = RemotingDecoder.GetPropertyValue<string>(inputObject, nameof(User));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same.

informationRecord.Computer = RemotingDecoder.GetPropertyValue<string>(inputObject, nameof(Computer));
informationRecord.ProcessId = RemotingDecoder.GetPropertyValue<uint>(inputObject, nameof(ProcessId));
informationRecord.NativeThreadId = RemotingDecoder.GetPropertyValue<uint>(inputObject, nameof(NativeThreadId));
informationRecord.ManagedThreadId = RemotingDecoder.GetPropertyValue<uint>(inputObject, nameof(ManagedThreadId));

return informationRecord;
}
Expand Down
Loading