Skip to content
Closed
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
22 changes: 16 additions & 6 deletions Rules/UseShouldProcessCorrectly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,27 @@ private bool SupportsShouldProcess(string cmdName)
var funcInfo = cmdInfo as FunctionInfo;
if (funcInfo != null
&& funcInfo.CmdletBinding
&& funcInfo.ScriptBlock != null
&& funcInfo.ScriptBlock.Attributes != null)
&& funcInfo.ScriptBlock != null)
{
foreach (var attr in funcInfo.ScriptBlock.Attributes)
try
{
var cmdletBindingAttr = attr as CmdletBindingAttribute;
if (cmdletBindingAttr != null)
if (funcInfo.ScriptBlock.Attributes != null)
{
return cmdletBindingAttr.SupportsShouldProcess;
foreach (var attr in funcInfo.ScriptBlock.Attributes)
{
var cmdletBindingAttr = attr as CmdletBindingAttribute;
if (cmdletBindingAttr != null)
{
return cmdletBindingAttr.SupportsShouldProcess;
}
}
}
}
catch (RuntimeException)
{
// The call to .Attributes on funcInfo.ScriptBlock.Attributes can throw if the attribute is custom and defined in a different file, therefore no action is being taken in this case
}

}

return false;
Expand Down