FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

WIP Fix Exception when trying to analyze custom attribute that is being defined in different file by bergmeister · Pull Request #995 · PowerShell/PSScriptAnalyzer · GitHub

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 16 additions & 6 deletions Rules/UseShouldProcessCorrectly.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL